Skip to content

Commit 5b880b2

Browse files
authored
fix(help): fix a bug where help was not available inside a project. (#2146)
Also adding a bunch of e2e improvements, and fixing another bug where help might not work with our published d.ts and map files.
1 parent 5a40a85 commit 5b880b2

File tree

6 files changed

+41
-15
lines changed

6 files changed

+41
-15
lines changed

packages/angular-cli/commands/help.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ const commandsToIgnore = [
1515
const HelpCommand = Command.extend({
1616
name: 'help',
1717
description: 'Shows help for the CLI',
18-
works: 'outsideProject',
18+
works: 'everywhere',
1919

2020
availableOptions: [],
2121

2222
run: function (commandOptions: any) {
2323
let commandFiles = fs.readdirSync(__dirname)
24+
// Remove files that are not JavaScript
25+
.filter(file => file.match(/\.js$/))
2426
.map(file => path.parse(file).name)
2527
.map(file => file.toLowerCase());
2628

scripts/publish/build.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Promise.resolve()
5555
}, Promise.resolve());
5656
})
5757
.then(() => console.log('Copying uncompiled resources...'))
58-
.then(() => glob(path.join(packagesRoot, '**/*')))
58+
.then(() => glob(path.join(packagesRoot, '**/*'), { dot: true }))
5959
.then(files => {
6060
console.log(` Found ${files.length} files...`);
6161
return files
@@ -88,8 +88,8 @@ Promise.resolve()
8888

8989
// The only remaining file we want to ignore is tsconfig and spec files.
9090
return !(/tsconfig\.json$/.test(fileName))
91-
&& !(/\.spec\./.test(fileName))
92-
&& !(/[\/\\]tests[\/\\]/.test(fileName));
91+
&& !(/\.spec\./.test(fileName))
92+
&& !(/[\/\\]tests[\/\\]/.test(fileName));
9393
})
9494
.map((fileName) => {
9595
const source = path.join(packagesRoot, fileName);

tests/e2e/setup/100-npm-link.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
import {join} from 'path';
12
import {npm, exec} from '../utils/process';
23

34

45
export default function (argv: any) {
56
return Promise.resolve()
6-
.then(() => argv.nolink || npm('link'))
7+
.then(() => {
8+
if (argv.nolink) {
9+
return;
10+
}
11+
12+
const distAngularCli = join(__dirname, '../../../dist/angular-cli');
13+
const oldCwd = process.cwd();
14+
process.chdir(distAngularCli);
15+
return npm('link')
16+
.then(() => process.chdir(oldCwd));
17+
})
718
.then(() => exec(process.platform.startsWith('win') ? 'where' : 'which', 'ng'));
819
}

tests/e2e/setup/500-create-project.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ export default function(argv: any) {
2525
return Promise.resolve()
2626
.then(() => createProject)
2727
.then(() => updateJsonFile('package.json', json => {
28-
const dist = '../../../dist/';
29-
json['devDependencies']['angular-cli'] = join(__dirname, dist, 'angular-cli');
30-
json['devDependencies']['@angular-cli/ast-tools'] = join(__dirname, dist, 'ast-tools');
31-
json['devDependencies']['@angular-cli/base-href-webpack'] =
32-
join(__dirname, dist, 'base-href-webpack');
28+
const dist = join(__dirname, '../../../dist/');
29+
json['devDependencies']['angular-cli'] = join(dist, 'angular-cli');
30+
json['devDependencies']['@angular-cli/ast-tools'] = join(dist, 'ast-tools');
31+
json['devDependencies']['@angular-cli/base-href-webpack'] = join(dist, 'base-href-webpack');
3332
}))
3433
.then(() => {
3534
if (argv.nightly) {

tests/e2e/tests/commands/help.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {silentNg} from '../../utils/process';
2+
3+
4+
export default function() {
5+
const projectDir = process.cwd();
6+
return Promise.resolve()
7+
.then(() => silentNg('help'))
8+
.then(() => process.chdir('/'))
9+
.then(() => silentNg('help'))
10+
.then(() => process.chdir(projectDir));
11+
}

tests/e2e/utils/process.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ let _processes: child_process.ChildProcess[] = [];
1313

1414
function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<string> {
1515
let stdout = '';
16+
let stderr = '';
1617
const cwd = process.cwd();
1718
console.log(white(
1819
` ==========================================================================================`
@@ -42,9 +43,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
4243
.forEach(line => console.log(' ' + line));
4344
});
4445
npmProcess.stderr.on('data', (data: Buffer) => {
45-
if (options.silent) {
46-
return;
47-
}
46+
stderr += data.toString('utf-8');
4847
data.toString('utf-8')
4948
.split(/[\n\r]+/)
5049
.filter(line => line !== '')
@@ -62,7 +61,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<strin
6261
if (!error) {
6362
resolve(stdout);
6463
} else {
65-
err.message += `${error}...`;
64+
err.message += `${error}...\n\nSTDOUT:\n${stdout}\n`;
6665
reject(err);
6766
}
6867
});
@@ -96,12 +95,16 @@ export function silentExecAndWaitForOutputToMatch(cmd: string, args: string[], m
9695

9796
export function ng(...args: string[]) {
9897
if (args[0] == 'build') {
99-
return _exec({silent: true}, 'ng', args);
98+
return silentNg(...args);
10099
} else {
101100
return _exec({}, 'ng', args);
102101
}
103102
}
104103

104+
export function silentNg(...args: string[]) {
105+
return _exec({silent: true}, 'ng', args);
106+
}
107+
105108
export function silentNpm(...args: string[]) {
106109
return _exec({silent: true}, 'npm', args);
107110
}

0 commit comments

Comments
 (0)