Skip to content

Commit 812ae27

Browse files
committed
Separate availableOptions and blueprints into .options.ts.
1 parent 39fa206 commit 812ae27

19 files changed

+191
-168
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const CommandOptions = [
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, default: false },
11+
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
12+
{ name: 'vendor-chunk', type: Boolean, default: true, aliases: ['vc'] },
13+
{ name: 'base-href', type: String, default: '/', 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+
]);

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

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,10 @@
11
import { BuildOptions } from '../models/webpack-config';
2+
import { availableOptions, CommandOptions } from './build.options';
23

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

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

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

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

4820
run: function (commandOptions: BuildTaskOptions) {
4921
return require('./build.run').default.call(this, commandOptions);
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: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ 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

@@ -32,17 +33,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
3233

3334
// Override default help to hide ember blueprints
3435
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-
});
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$/) && !file.match(/\.run.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();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { BaseBuildCommandOptions } from './build';
2+
3+
import { CliConfig } from '../models/config';
4+
const PortFinder = require('portfinder');
5+
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
6+
7+
PortFinder.basePort = 49152;
8+
9+
const defaultPort = process.env.PORT || config.get('defaults.serve.port');
10+
const defaultHost = config.get('defaults.serve.host');
11+
12+
export const availableOptions: any = BaseBuildCommandOptions.concat([
13+
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
14+
{
15+
name: 'host',
16+
type: String,
17+
default: defaultHost,
18+
aliases: ['H'],
19+
description: `Listens only on ${defaultHost} by default`
20+
},
21+
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
22+
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
23+
{
24+
name: 'live-reload-host',
25+
type: String,
26+
aliases: ['lrh'],
27+
description: 'Defaults to host'
28+
},
29+
{
30+
name: 'live-reload-base-url',
31+
type: String,
32+
aliases: ['lrbu'],
33+
description: 'Defaults to baseURL'
34+
},
35+
{
36+
name: 'live-reload-port',
37+
type: Number,
38+
aliases: ['lrp'],
39+
description: '(Defaults to port number within [49152...65535])'
40+
},
41+
{
42+
name: 'live-reload-live-css',
43+
type: Boolean,
44+
default: true,
45+
description: 'Whether to live reload CSS (default true)'
46+
},
47+
{ name: 'ssl', type: Boolean, default: false },
48+
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
49+
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
50+
{
51+
name: 'open',
52+
type: Boolean,
53+
default: false,
54+
aliases: ['o'],
55+
description: 'Opens the url in default browser',
56+
},
57+
{
58+
name: 'hmr',
59+
type: Boolean,
60+
default: false,
61+
description: 'Enable hot module replacement',
62+
}
63+
]);

0 commit comments

Comments
 (0)