8000 fix(@angular/cli): show blueprints in completion script · shmool/angular-cli@26b1ee4 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 26b1ee4

Browse files
catullfilipesilva
authored andcommitted
fix(@angular/cli): show blueprints in completion script
Close angular#4571
1 parent e55cb82 commit 26b1ee4

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

packages/@angular/cli/commands/completion.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const stringUtils = require('ember-cli-string-utils');
77
const Command = require('../ember-cli/lib/models/command');
88
const lookupCommand = require('../ember-cli/lib/cli/lookup-command');
99

10-
function extractOptions(opts: any): String {
11-
const output: String[] = [];
10+
function extractOptions(opts: any): string {
11+
const output: string[] = [];
1212

1313
for (let index = 0; index < opts.length; index++) {
1414
const element = opts[index];
@@ -21,20 +21,30 @@ function extractOptions(opts: any): String {
2121
return output.sort().join(' ');
2222
}
2323

24+
function extractBlueprints(opts: any): string {
25+
const output: string[] = [];
26+
27+
for (let index = 0; index < opts.length; index++) {
28+
const element = opts[index];
29+
output.push(element.name);
30+
}
31+
32+
return output.sort().join(' ');
33+
}
34+
2435
export interface CompletionCommandOptions {
2536
all?: boolean;
2637
bash?: boolean;
2738
zsh?: boolean;
2839
};
2940

3041
const commandsToIgnore = [
31-
'easter-egg',
32-
'init',
3342
'destroy',
34-
'github-pages-deploy' // errors because there is no base github-pages command
43+
'easter-egg',
44+
'init'
3545
];
3646

37-
const optsNg: String[] = [];
47+
const optsNg: string[] = [];
3848

3949
const CompletionCommand = Command.extend({
4050
name: 'completion',
@@ -70,7 +80,7 @@ const CompletionCommand = Command.extend({
7080

7181
commandFiles.forEach(cmd => {
7282
const Command = lookupCommand(commandMap, cmd);
73-
const com: String[] = [];
83+
const com: string[] = [];
7484

7585
const command = new Command({
7686
ui: this.ui,
@@ -83,21 +93,26 @@ const CompletionCommand = Command.extend({
8393
com.push(command.name);
8494

8595
if (command.aliases) {
86-
command.aliases.forEach((element: String) => {
96+
command.aliases.forEach((element: string) => {
8797
optsNg.push(element);
8898
com.push(element);
8999
});
90100
}
91101

102+
let opts = '';
103+
if (command.blueprints && command.blueprints[0]) {
104+
opts += extractBlueprints(command.blueprints);
105+
}
106+
92107
if (command.availableOptions && command.availableOptions[0]) {
93-
let opts = extractOptions (command.availableOptions);
108+
opts += extractOptions(command.availableOptions);
94109
caseBlock = caseBlock + ' ' + com.sort().join('|') + ') opts="' + opts + '" ;;\n';
95110
}
96111
});
97112

98113
caseBlock = 'ng|help) opts="' + optsNg.sort().join(' ') + '" ;;\n' +
99-
caseBlock +
100-
' *) opts="" ;;';
114+
caseBlock +
115+
' *) opts="" ;;';
101116

102117
console.log(stripIndent`
103118
###-begin-ng-completion###

packages/@angular/cli/commands/generate.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
77
const Blueprint = require('../ember-cli/lib/models/blueprint');
88
const SilentError = require('silent-error');
99

10+
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
11+
const blueprints = blueprintList
12+
.filter(bp => bp.indexOf('-test') === -1)
13+
.filter(bp => bp !== 'ng2')
14+
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
1015

1116
const GenerateCommand = EmberGenerateCommand.extend({
1217
name: 'generate',
1318

14-
beforeRun: function(rawArgs: string[]) {
19+
blueprints: blueprints,
20+
21+
beforeRun: function (rawArgs: string[]) {
1522
if (!rawArgs.length) {
1623
return;
1724
}
@@ -22,7 +29,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
2229
if (rawArgs[0] !== '--help' &&
2330
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
2431
SilentError.debugOrThrow('@angular/cli/commands/generate',
25-
`Invalid blueprint: ${rawArgs[0]}`);
32+
`Invalid blueprint: ${rawArgs[0]}`);
2633
}
2734

2835
if (!rawArgs[1]) {
@@ -31,20 +38,9 @@ const GenerateCommand = EmberGenerateCommand.extend({
3138
}
3239

3340
// Override default help to hide ember blueprints
34-
EmberGenerateCommand.prototype.printDetailedHelp = function() {
35-
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
36-
const blueprints = blueprintList
37-
.filter(bp => bp.indexOf('-test') === -1)
38-
.filter(bp => bp !== 'ng2')
39-
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
40-
41-
let output = '';
42-
blueprints
43-
.forEach(function (bp) {
44-
output += bp.printBasicHelp(false) + os.EOL;
45-
});
41+
EmberGenerateCommand.prototype.printDetailedHelp = function () {
4642
this.ui.writeLine(chalk.cyan(' Available blueprints'));
47-
this.ui.writeLine(output);
43+
this.ui.writeLine(blueprints.map(bp => bp.printBasicHelp(false)).join(os.EOL));
4844
};
4945

5046
return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);

0 commit comments

Comments
 (0)
0