diff --git a/packages/@angular/cli/commands/completion.ts b/packages/@angular/cli/commands/completion.ts index 620a943714c5..5a89bdef2deb 100644 --- a/packages/@angular/cli/commands/completion.ts +++ b/packages/@angular/cli/commands/completion.ts @@ -7,8 +7,8 @@ const stringUtils = require('ember-cli-string-utils'); const Command = require('../ember-cli/lib/models/command'); const lookupCommand = require('../ember-cli/lib/cli/lookup-command'); -function extractOptions(opts: any): String { - const output: String[] = []; +function extractOptions(opts: any): string { + const output: string[] = []; for (let index = 0; index < opts.length; index++) { const element = opts[index]; @@ -21,6 +21,17 @@ function extractOptions(opts: any): String { return output.sort().join(' '); } +function extractBlueprints(opts: any): string { + const output: string[] = []; + + for (let index = 0; index < opts.length; index++) { + const element = opts[index]; + output.push(element.name); + } + + return output.sort().join(' '); +} + export interface CompletionCommandOptions { all?: boolean; bash?: boolean; @@ -28,13 +39,12 @@ export interface CompletionCommandOptions { }; const commandsToIgnore = [ - 'easter-egg', - 'init', 'destroy', - 'github-pages-deploy' // errors because there is no base github-pages command + 'easter-egg', + 'init' ]; -const optsNg: String[] = []; +const optsNg: string[] = []; const CompletionCommand = Command.extend({ name: 'completion', @@ -70,7 +80,7 @@ const CompletionCommand = Command.extend({ commandFiles.forEach(cmd => { const Command = lookupCommand(commandMap, cmd); - const com: String[] = []; + const com: string[] = []; const command = new Command({ ui: this.ui, @@ -83,21 +93,26 @@ const CompletionCommand = Command.extend({ com.push(command.name); if (command.aliases) { - command.aliases.forEach((element: String) => { + command.aliases.forEach((element: string) => { optsNg.push(element); com.push(element); }); } + let opts = ''; + if (command.blueprints && command.blueprints[0]) { + opts += extractBlueprints(command.blueprints); + } + if (command.availableOptions && command.availableOptions[0]) { - let opts = extractOptions (command.availableOptions); + opts += extractOptions(command.availableOptions); caseBlock = caseBlock + ' ' + com.sort().join('|') + ') opts="' + opts + '" ;;\n'; } }); caseBlock = 'ng|help) opts="' + optsNg.sort().join(' ') + '" ;;\n' + - caseBlock + - ' *) opts="" ;;'; + caseBlock + + ' *) opts="" ;;'; console.log(stripIndent` ###-begin-ng-completion### diff --git a/packages/@angular/cli/commands/generate.ts b/packages/@angular/cli/commands/generate.ts index 822d7a5d10e8..e449dba13b8d 100644 --- a/packages/@angular/cli/commands/generate.ts +++ b/packages/@angular/cli/commands/generate.ts @@ -7,11 +7,18 @@ const EmberGenerateCommand = require('../ember-cli/lib/commands/generate'); const Blueprint = require('../ember-cli/lib/models/blueprint'); const SilentError = require('silent-error'); +const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints')); +const blueprints = blueprintList + .filter(bp => bp.indexOf('-test') === -1) + .filter(bp => bp !== 'ng2') + .map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp))); const GenerateCommand = EmberGenerateCommand.extend({ name: 'generate', - beforeRun: function(rawArgs: string[]) { + blueprints: blueprints, + + beforeRun: function (rawArgs: string[]) { if (!rawArgs.length) { return; } @@ -22,7 +29,7 @@ const GenerateCommand = EmberGenerateCommand.extend({ if (rawArgs[0] !== '--help' && !fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) { SilentError.debugOrThrow('@angular/cli/commands/generate', - `Invalid blueprint: ${rawArgs[0]}`); + `Invalid blueprint: ${rawArgs[0]}`); } if (!rawArgs[1]) { @@ -31,20 +38,9 @@ const GenerateCommand = EmberGenerateCommand.extend({ } // Override default help to hide ember blueprints - EmberGenerateCommand.prototype.printDetailedHelp = function() { - const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints')); - const blueprints = blueprintList - .filter(bp => bp.indexOf('-test') === -1) - .filter(bp => bp !== 'ng2') - .map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp))); - - let output = ''; - blueprints - .forEach(function (bp) { - output += bp.printBasicHelp(false) + os.EOL; - }); + EmberGenerateCommand.prototype.printDetailedHelp = function () { this.ui.writeLine(chalk.cyan(' Available blueprints')); - this.ui.writeLine(output); + this.ui.writeLine(blueprints.map(bp => bp.printBasicHelp(false)).join(os.EOL)); }; return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);