Skip to content

Commit afeec30

Browse files
committed
Factored out availableOptions to _.options.ts.
1 parent f2f02a6 commit afeec30

22 files changed

+214
-195
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const CommandOptions: any = [
2+
{
3+
name: 'target',
4+
type: String,
5+
default: 'development',
6+
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
7+
},
8+
{ name: 'environment', type: String, aliases: ['e'] },
9+
{ name: 'output-path', type: 'Path', aliases: ['op'] },
10+
{ name: 'aot', type: Boolean },
11+
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
12+
{ name: 'vendor-chunk', type: Boolean, default: true, aliases: ['vc'] },
13+
{ name: 'base-href', type: String, aliases: ['bh'] },
14+
{ name: 'deploy-url', type: String, aliases: ['d'] },
15+
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
16+
{ name: 'progress', type: Boolean, default: true, aliases: ['pr'] },
17+
{ name: 'i18n-file', type: String },
18+
{ name: 'i18n-format', type: String },
19+
{ name: 'locale', type: String },
20+
{ name: 'extract-css', type: Boolean, aliases: ['ec'] },
21+
{
22+
name: 'output-hashing',
23+
type: String,
24+
values: ['none', 'all', 'media', 'bundles'],
25+
description: 'define the output filename cache-busting hashing mode',
26+
aliases: ['oh']
27+
},
28+
];
29+
30+
export const availableOptions = CommandOptions.concat([
31+
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
32+
]);
Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11
import { BuildOptions } from '../models/build-options';
2+
import { availableOptions, CommandOptions } from './build.options';
23
import { Version } from '../upgrade/version';
34

45
const Command = require('../ember-cli/lib/models/command');
56

67
// defaults for BuildOptions
7-
export const BaseBuildCommandOptions: any = [
8-
{
9-
name: 'target',
10-
type: String,
11-
default: 'development',
12-
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
13-
},
14-
{ name: 'environment', type: String, aliases: ['e'] },
15-
{ name: 'output-path', type: 'Path', aliases: ['op'] },
16-
{ name: 'aot', type: Boolean },
17-
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
18-
{ name: 'vendor-chunk', type: Boolean, default: true, aliases: ['vc'] },
19-
{ name: 'base-href', type: String, aliases: ['bh'] },
20-
{ name: 'deploy-url', type: String, aliases: ['d'] },
21-
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
22-
{ name: 'progress', type: Boolean, default: true, aliases: ['pr'] },
23-
{ name: 'i18n-file', type: String },
24-
{ name: 'i18n-format', type: String },
25-
{ name: 'locale', type: String },
26-
{ name: 'extract-css', type: Boolean, aliases: ['ec'] },
27-
{
28-
name: 'output-hashing',
29-
type: String,
30-
values: ['none', 'all', 'media', 'bundles'],
31-
description: 'define the output filename cache-busting hashing mode',
32-
aliases: ['oh']
33-
},
34-
];
8+
export const BaseBuildCommandOptions: any = CommandOptions;
359

3610
export interface BuildTaskOptions extends BuildOptions {
3711
watch?: boolean;
@@ -42,9 +16,7 @@ const BuildCommand = Command.extend({
4216
description: 'Builds your app and places it into the output path (dist/ by default).',
4317
aliases: ['b'],
4418

45-
availableOptions: BaseBuildCommandOptions.concat([
46-
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
47-
]),
19+
availableOptions: availableOptions,
4820

4921
run: function (commandOptions: BuildTaskOptions) {
5022
const project = this.project;
@@ -63,6 +35,5 @@ const BuildCommand = Command.extend({
6335
}
6436
});
6537

66-
6738
BuildCommand.overrideCore = true;
6839
export default BuildCommand;

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export interface CompletionCommandOptions {
2929

3030
const commandsToIgnore = [
3131
'easter-egg',
32-
'destroy',
33-
'github-pages-deploy' // errors because there is no base github-pages command
32+
'destroy'
3433
];
3534

3635
const optsNg: String[] = [];
@@ -40,16 +39,16 @@ const CompletionCommand = Command.extend({
4039
description: 'Adds autocomplete functionality to `ng` commands and subcommands',
4140
works: 'everywhere',
4241
availableOptions: [
43-
{ name: 'all', type: Boolean, default: true, aliases: ['a'] },
44-
{ name: 'bash', type: Boolean, default: false, aliases: ['b'] },
45-
{ name: 'zsh', type: Boolean, default: false, aliases: ['z'] }
42+
{ name: 'all', type: Boolean, default: true, aliases: ['a'] },
43+
{ name: 'bash', type: Boolean, default: false, aliases: ['b'] },
44+
{ name: 'zsh', type: Boolean, default: false, aliases: ['z'] }
4645
],
4746

4847
run: function (commandOptions: CompletionCommandOptions) {
4948
commandOptions.all = !commandOptions.bash && !commandOptions.zsh;
5049

5150
const commandFiles = fs.readdirSync(__dirname)
52-
.filter(file => file.match(/\.ts$/) && !file.match(/\.run.ts$/))
51+
.filter(file => file.match(/\.ts$/) && !file.match(/\.options.ts$/))
5352
.map(file => path.parse(file).name)
5453
.filter(file => {
5554
return commandsToIgnore.indexOf(file) < 0;
@@ -89,14 +88,14 @@ const CompletionCommand = Command.extend({
8988
}
9089

9190
if (command.availableOptions && command.availableOptions[0]) {
92-
let opts = extractOptions (command.availableOptions);
91+
let opts = extractOptions(command.availableOptions);
9392
caseBlock = caseBlock + ' ' + com.sort().join('|') + ') opts="' + opts + '" ;;\n';
9493
}
9594
});
9695

9796
caseBlock = 'ng|help) opts="' + optsNg.sort().join(' ') + '" ;;\n' +
98-
caseBlock +
99-
' *) opts="" ;;';
97+
caseBlock +
98+
' *) opts="" ;;';
10099

101100
console.log(stripIndent`
102101
###-begin-ng-completion###
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
const Blueprint = require('../ember-cli/lib/models/blueprint');
5+
6+
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
7+
8+
export const blueprints = blueprintList
9+
.filter(bp => bp.indexOf('-test') === -1)
10+
.filter(bp => bp !== 'ng2')
11+
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import * as os from 'os';
44

5+
import { blueprints } from './generate.options';
6+
57
const chalk = require('chalk');
68
const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
7-
const Blueprint = require('../ember-cli/lib/models/blueprint');
89
const SilentError = require('silent-error');
910

1011

1112
const GenerateCommand = EmberGenerateCommand.extend({
1213
name: 'generate',
1314

14-
beforeRun: function(rawArgs: string[]) {
15+
beforeRun: function (rawArgs: string[]) {
1516
if (!rawArgs.length) {
1617
return;
1718
}
@@ -22,7 +23,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
2223
if (rawArgs[0] !== '--help' &&
2324
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
2425
SilentError.debugOrThrow('@angular/cli/commands/generate',
25-
`Invalid blueprint: ${rawArgs[0]}`);
26+
`Invalid blueprint: ${rawArgs[0]}`);
2627
}
2728

2829
if (!rawArgs[1]) {
@@ -31,18 +32,8 @@ const GenerateCommand = EmberGenerateCommand.extend({
3132
}
3233

3334
// 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-
});
35+
EmberGenerateCommand.prototype.printDetailedHelp = function () {
36+
let output = blueprints.map(bp => bp.printBasicHelp(false)).join(os.EOL);
4637
this.ui.writeLine(chalk.cyan(' Available blueprints'));
4738
this.ui.writeLine(output);
4839
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const availableOptions = [
2+
{ name: 'global', type: Boolean, 'default': false }
3+
];

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {CliConfig} from '../models/config';
1+
import { CliConfig } from '../models/config';
2+
import { availableOptions } from './get.options';
23

34
const SilentError = require('silent-error');
45
const Command = require('../ember-cli/lib/models/command');
@@ -14,9 +15,7 @@ const GetCommand = Command.extend({
1415
description: 'Get a value from the configuration.',
1516
works: 'everywhere',
1617

17-
availableOptions: [
18-
{ name: 'global', type: Boolean, 'default': false }
19-
],
18+
availableOptions: availableOptions,
2019

2120
run: function (commandOptions: GetOptions, rawArgs: string[]): Promise<void> {
2221
return new Promise<void>(resolve => {

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ const HelpCommand = Command.extend({
2121

2222
run: function (commandOptions: any, rawArgs: any) {
2323
let commandFiles = fs.readdirSync(__dirname)
24-
// Remove files that are not JavaScript or Typescript
25-
.filter(file => file.match(/\.(j|t)s$/) && !file.match(/\.d.ts$/))
24+
// Remove files that are not pure command Typescript
25+
.filter(file => file.match(/\.ts$/) && !file.match(/\.d.ts$/) &&
26+
!file.match(/\.run.ts$/) && !file.match(/\.options.ts$/))
2627
.map(file => path.parse(file).name)
27-
.map(file => file.toLowerCase());
28-
29-
commandFiles = commandFiles.filter(file => {
30-
return commandsToIgnore.indexOf(file) < 0;
31-
});
28+
.map(file => file.toLowerCase())
29+
.filter(file => commandsToIgnore.indexOf(file) < 0);
3230

3331
let commandMap = commandFiles.reduce((acc: any, curr: string) => {
3432
let classifiedName = stringUtils.classify(curr);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const availableOptions: any = [
2+
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
3+
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
4+
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
5+
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
6+
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
7+
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
8+
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
9+
{ name: 'name', type: String, default: '', aliases: ['n'] },
10+
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
11+
{ name: 'style', type: String, default: 'css' },
12+
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
13+
{ name: 'routing', type: Boolean, default: false },
14+
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
15+
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
16+
];

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
const Command = require('../ember-cli/lib/models/command');
2+
import { availableOptions } from './init.options';
23

34
const InitCommand: any = Command.extend({
45
name: 'init',
56
description: 'Creates a new Angular CLI project in the current folder.',
67
aliases: ['u', 'update', 'i'],
78
works: 'everywhere',
89

9-
availableOptions: [
10-
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
11-
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
12-
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
13-
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
14-
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
15-
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
16-
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
17-
{ name: 'name', type: String, default: '', aliases: ['n'] },
18-
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
19-
{ name: 'style', type: String, default: 'css' },
20-
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
21-
{ name: 'routing', type: Boolean, default: false },
22-
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
23-
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
24-
],
10+
availableOptions: availableOptions,
2511

2612
anonymousOptions: ['<glob-pattern>'],
2713

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export const availableOptions: any = [
2+
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
3+
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
4+
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
5+
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
6+
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
7+
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
8+
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
9+
{ name: 'directory', type: String, aliases: ['dir'] },
10+
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
11+
{ name: 'style', type: String, default: 'css' },
12+
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
13+
{ name: 'routing', type: Boolean, default: false },
14+
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
15+
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
16+
];

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as chalk from 'chalk';
22
import InitCommand from './init';
33
import { validateProjectName } from '../utilities/validate-project-name';
4+
import { availableOptions } from './new.options';
45

56
const Command = require('../ember-cli/lib/models/command');
67
const Project = require('../ember-cli/lib/models/project');
@@ -11,22 +12,7 @@ const NewCommand = Command.extend({
1112
description: `Creates a new directory and runs ${chalk.green('ng init')} in it.`,
1213
works: 'outsideProject',
1314

14-
availableOptions: [
15-
{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] },
16-
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
17-
{ name: 'link-cli', type: Boolean, default: false, aliases: ['lc'] },
18-
{ name: 'skip-npm', type: Boolean, default: false, aliases: ['sn'] },
19-
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
20-
{ name: 'skip-tests', type: Boolean, default: false, aliases: ['st'] },
21-
{ name: 'skip-commit', type: Boolean, default: false, aliases: ['sc'] },
22-
{ name: 'directory', type: String, aliases: ['dir'] },
23-
{ name: 'source-dir', type: String, default: 'src', aliases: ['sd'] },
24-
{ name: 'style', type: String, default: 'css' },
25-
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
26-
{ name: 'routing', type: Boolean, default: false },
27-
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
28-
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
29-
],
15+
availableOptions: availableOptions,
3016

3117
run: function (commandOptions: any, rawArgs: string[]) {
3218
const packageName = rawArgs.shift();

0 commit comments

Comments
 (0)