Skip to content

Commit c93ffca

Browse files
committed
refactor(build): consolidate build options
1 parent cd296bc commit c93ffca

20 files changed

+237
-323
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"walk-sync": "^0.2.6",
116116
"webpack": "2.2.0",
117117
"webpack-dev-server": "2.2.0-rc.0",
118-
"webpack-merge": "^0.14.0",
118+
"webpack-merge": "^2.4.0",
119119
"webpack-sources": "^0.1.3",
120120
"zone.js": "^0.7.2"
121121
},

packages/angular-cli/commands/build.run.ts

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,8 @@
11
import { Version } from '../upgrade/version';
22
import WebpackBuild from '../tasks/build-webpack';
3-
import { BuildOptions } from './build';
4-
5-
export default function buildRun(commandOptions: BuildOptions) {
6-
if (commandOptions.environment === '') {
7-
if (commandOptions.target === 'development') {
8-
commandOptions.environment = 'dev';
9-
}
10-
if (commandOptions.target === 'production') {
11-
commandOptions.environment = 'prod';
12-
}
13-
}
14-
15-
if (!commandOptions.outputHashing) {
16-
if (commandOptions.target === 'development') {
17-
commandOptions.outputHashing = 'none';
18-
}
19-
if (commandOptions.target === 'production') {
20-
commandOptions.outputHashing = 'all';
21-
}
22-
}
23-
24-
if (typeof commandOptions.sourcemap === 'undefined') {
25-
if (commandOptions.target == 'development') {
26-
commandOptions.sourcemap = true;
27-
}
28-
if (commandOptions.target == 'production') {
29-
commandOptions.sourcemap = false;
30-
}
31-
}
3+
import { BuildTaskOptions } from './build';
324

5+
export default function buildRun(commandOptions: BuildTaskOptions) {
336
const project = this.project;
347

358
// Check angular version.
@@ -38,9 +11,6 @@ export default function buildRun(commandOptions: BuildOptions) {
3811
const buildTask = new WebpackBuild({
3912
cliProject: project,
4013
ui: this.ui,
41-
outputPath: commandOptions.outputPath,
42-
target: commandOptions.target,
43-
environment: commandOptions.environment,
4414
});
4515

4616
return buildTask.run(commandOptions);

packages/angular-cli/commands/build.ts

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,51 @@
1+
import { BuildOptions } from '../models/webpack-config';
2+
13
const Command = require('../ember-cli/lib/models/command');
24

3-
export interface BuildOptions {
4-
target?: string;
5-
environment?: string;
6-
outputPath?: string;
5+
// 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, default: false },
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+
];
34+
35+
export interface BuildTaskOptions extends BuildOptions {
736
watch?: boolean;
8-
watcher?: string;
9-
supressSizes: boolean;
10-
baseHref?: string;
11-
aot?: boolean;
12-
sourcemap?: boolean;
13-
vendorChunk?: boolean;
14-
verbose?: boolean;
15-
progress?: boolean;
16-
i18nFile?: string;
17-
i18nFormat?: string;
18-
locale?: string;
19-
deployUrl?: string;
20-
outputHashing?: string;
21-
extractCss?: boolean | null;
2237
}
2338

2439
const BuildCommand = Command.extend({
2540
name: 'build',
2641
description: 'Builds your app and places it into the output path (dist/ by default).',
2742
aliases: ['b'],
2843

29-
availableOptions: [
30-
{
31-
name: 'target',
32-
type: String,
33-
default: 'development',
34-
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
35-
},
36-
{ name: 'environment', type: String, default: '', aliases: ['e'] },
37-
{ name: 'output-path', type: 'Path', default: null, aliases: ['o'] },
38-
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
39-
{ name: 'watcher', type: String },
40-
{ name: 'suppress-sizes', type: Boolean, default: false },
41-
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
42-
{ name: 'aot', type: Boolean, default: false },
43-
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
44-
{ name: 'vendor-chunk', type: Boolean, default: true },
45-
{ name: 'verbose', type: Boolean, default: false },
46-
{ name: 'progress', type: Boolean, default: true },
47-
{ name: 'i18n-file', type: String, default: null },
48-
{ name: 'i18n-format', type: String, default: null },
49-
{ name: 'locale', type: String, default: null },
50-
{ name: 'deploy-url', type: String, default: null, aliases: ['d'] },
51-
{
52-
name: 'output-hashing',
53-
type: String,
54-
values: ['none', 'all', 'media', 'bundles'],
55-
description: 'define the output filename cache-busting hashing mode'
56-
},
57-
{ name: 'extract-css', type: Boolean, default: true }
58-
],
44+
availableOptions: BaseBuildCommandOptions.concat([
45+
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
46+
]),
5947

60-
run: function (commandOptions: BuildOptions) {
48+
run: function (commandOptions: BuildTaskOptions) {
6149
return require('./build.run').default.call(this, commandOptions);
6250
}
6351
});

packages/angular-cli/commands/serve.run.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,19 @@ PortFinder.basePort = 49152;
1111
const getPort = <any>denodeify(PortFinder.getPort);
1212

1313
export default function serveRun(commandOptions: ServeTaskOptions) {
14-
if (commandOptions.environment === '') {
15-
if (commandOptions.target === 'development') {
16-
commandOptions.environment = 'dev';
17-
}
18-
if (commandOptions.target === 'production') {
19-
commandOptions.environment = 'prod';
20-
}
21-
}
22-
23-
// default to extractCss to true on prod target
24-
if (typeof commandOptions.extractCss === 'undefined') {
25-
commandOptions.extractCss = commandOptions.target === 'production';
26-
}
27-
2814
// Check angular version.
2915
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
3016
commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;
3117

3218
return checkExpressPort(commandOptions)
3319
.then(() => autoFindLiveReloadPort(commandOptions))
3420
.then((opts: ServeTaskOptions) => {
35-
commandOptions = assign({}, opts, {
36-
baseURL: this.project.config(commandOptions.target).baseURL || '/'
37-
});
38-
3921
const serve = new ServeWebpackTask({
4022
ui: this.ui,
4123
project: this.project,
4224
});
4325

44-
return serve.run(commandOptions);
26+
return serve.run(opts);
4527
});
4628
}
4729

packages/angular-cli/commands/serve.ts

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,35 @@
1+
import { BuildOptions } from '../models/webpack-config';
2+
import { BaseBuildCommandOptions } from './build';
3+
14
const PortFinder = require('portfinder');
25
const Command = require('../ember-cli/lib/models/command');
36

47
PortFinder.basePort = 49152;
58

69
const defaultPort = process.env.PORT || 4200;
710

8-
export interface ServeTaskOptions {
11+
export interface ServeTaskOptions extends BuildOptions {
912
port?: number;
1013
host?: string;
1114
proxyConfig?: string;
12-
watcher?: string;
1315
liveReload?: boolean;
1416
liveReloadHost?: string;
1517
liveReloadPort?: number;
1618
liveReloadBaseUrl?: string;
1719
liveReloadLiveCss?: boolean;
18-
target?: string;
19-
environment?: string;
2020
ssl?: boolean;
2121
sslKey?: string;
2222
sslCert?: string;
23-
aot?: boolean;
24-
sourcemap?: boolean;
25-
verbose?: boolean;
26-
progress?: boolean;
2723
open?: boolean;
28-
vendorChunk?: boolean;
2924
hmr?: boolean;
30-
i18nFile?: string;
31-
i18nFormat?: string;
32-
locale?: string;
33-
extractCss?: boolean | null;
3425
}
3526

3627
const ServeCommand = Command.extend({
3728
name: 'serve',
3829
description: 'Builds and serves your app, rebuilding on file changes.',
3930
aliases: ['server', 's'],
4031

41-
availableOptions: [
32+
availableOptions: BaseBuildCommandOptions.concat([
4233
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
4334
{
4435
name: 'host',
@@ -48,7 +39,6 @@ const ServeCommand = Command.extend({
4839
description: 'Listens only on localhost by default'
4940
},
5041
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
51-
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
5242
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
5343
{
5444
name: 'live-reload-host',
@@ -74,21 +64,9 @@ const ServeCommand = Command.extend({
7464
default: true,
7565
description: 'Whether to live reload CSS (default true)'
7666
},
77-
{
78-
name: 'target',
79-
type: String,
80-
default: 'development',
81-
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
82-
},
83-
{ name: 'environment', type: String, default: '', aliases: ['e'] },
8467
{ name: 'ssl', type: Boolean, default: false },
8568
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
8669
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
87-
{ name: 'aot', type: Boolean, default: false },
88-
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
89-
{ name: 'vendor-chunk', type: Boolean, default: true },
90-
{ name: 'verbose', type: Boolean, default: false },
91-
{ name: 'progress', type: Boolean, default: true },
9270
{
9371
name: 'open',
9472
type: Boolean,
@@ -101,12 +79,8 @@ const ServeCommand = Command.extend({
10179
type: Boolean,
10280
default: false,
10381
description: 'Enable hot module replacement',
104-
},
105-
{ name: 'i18n-file', type: String, default: null },
106-
{ name: 'i18n-format', type: String, default: null },
107-
{ name: 'locale', type: String, default: null },
108-
{ name: 'extract-css', type: Boolean, default: null }
109-
],
82+
}
83+
]),
11084

11185
run: function(commandOptions: ServeTaskOptions) {
11286
return require('./serve.run').default.call(this, commandOptions);

packages/angular-cli/models/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/angular-cli/models/webpack-build-development.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)