Skip to content

Commit

Permalink
refactor(build): consolidate build options
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jan 19, 2017
1 parent e5ef996 commit dedf216
Show file tree
Hide file tree
Showing 24 changed files with 351 additions and 411 deletions.
34 changes: 2 additions & 32 deletions packages/angular-cli/commands/build.run.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { Version } from '../upgrade/version';
import WebpackBuild from '../tasks/build-webpack';
import { BuildOptions } from './build';

export default function buildRun(commandOptions: BuildOptions) {
if (commandOptions.environment === '') {
if (commandOptions.target === 'development') {
commandOptions.environment = 'dev';
}
if (commandOptions.target === 'production') {
commandOptions.environment = 'prod';
}
}

if (!commandOptions.outputHashing) {
if (commandOptions.target === 'development') {
commandOptions.outputHashing = 'none';
}
if (commandOptions.target === 'production') {
commandOptions.outputHashing = 'all';
}
}

if (typeof commandOptions.sourcemap === 'undefined') {
if (commandOptions.target == 'development') {
commandOptions.sourcemap = true;
}
if (commandOptions.target == 'production') {
commandOptions.sourcemap = false;
}
}
import { BuildTaskOptions } from './build';

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

// Check angular version.
Expand All @@ -38,9 +11,6 @@ export default function buildRun(commandOptions: BuildOptions) {
const buildTask = new WebpackBuild({
cliProject: project,
ui: this.ui,
outputPath: commandOptions.outputPath,
target: commandOptions.target,
environment: commandOptions.environment,
});

return buildTask.run(commandOptions);
Expand Down
86 changes: 37 additions & 49 deletions packages/angular-cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,51 @@
import { BuildOptions } from '../models/webpack-config';

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

export interface BuildOptions {
target?: string;
environment?: string;
outputPath?: string;
// defaults for BuildOptions
export const BaseBuildCommandOptions: any = [
{
name: 'target',
type: String,
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
},
{ name: 'environment', type: String, aliases: ['e'] },
{ name: 'output-path', type: 'Path', aliases: ['op'] },
{ name: 'aot', type: Boolean, default: false },
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
{ name: 'vendor-chunk', type: Boolean, default: true, aliases: ['vc'] },
{ name: 'base-href', type: String, default: '/', aliases: ['bh'] },
{ name: 'deploy-url', type: String, aliases: ['d'] },
{ name: 'verbose', type: Boolean, default: false, aliases: ['v'] },
{ name: 'progress', type: Boolean, default: true, aliases: ['pr'] },
{ name: 'i18n-file', type: String },
{ name: 'i18n-format', type: String },
{ name: 'locale', type: String },
{ name: 'extract-css', type: Boolean, aliases: ['ec']},
{
name: 'output-hashing',
type: String,
values: ['none', 'all', 'media', 'bundles'],
description: 'define the output filename cache-busting hashing mode',
aliases: ['oh']
},
];

export interface BuildTaskOptions extends BuildOptions {
watch?: boolean;
watcher?: string;
supressSizes: boolean;
baseHref?: string;
aot?: boolean;
sourcemap?: boolean;
vendorChunk?: boolean;
verbose?: boolean;
progress?: boolean;
i18nFile?: string;
i18nFormat?: string;
locale?: string;
deployUrl?: string;
outputHashing?: string;
extractCss?: boolean | null;
}

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

availableOptions: [
{
name: 'target',
type: String,
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
},
{ name: 'environment', type: String, default: '', aliases: ['e'] },
{ name: 'output-path', type: 'Path', default: null, aliases: ['o'] },
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
{ name: 'watcher', type: String },
{ name: 'suppress-sizes', type: Boolean, default: false },
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
{ name: 'aot', type: Boolean, default: false },
{ name: 'sourcemap', type: Boolean, aliases: ['sm'] },
{ name: 'vendor-chunk', type: Boolean, default: true },
{ name: 'verbose', type: Boolean, default: false },
{ name: 'progress', type: Boolean, default: true },
{ name: 'i18n-file', type: String, default: null },
{ name: 'i18n-format', type: String, default: null },
{ name: 'locale', type: String, default: null },
{ name: 'deploy-url', type: String, default: null, aliases: ['d'] },
{
name: 'output-hashing',
type: String,
values: ['none', 'all', 'media', 'bundles'],
description: 'define the output filename cache-busting hashing mode'
},
{ name: 'extract-css', type: Boolean, default: true }
],
availableOptions: BaseBuildCommandOptions.concat([
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] }
]),

run: function (commandOptions: BuildOptions) {
run: function (commandOptions: BuildTaskOptions) {
return require('./build.run').default.call(this, commandOptions);
}
});
Expand Down
20 changes: 1 addition & 19 deletions packages/angular-cli/commands/serve.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,19 @@ PortFinder.basePort = 49152;
const getPort = <any>denodeify(PortFinder.getPort);

export default function serveRun(commandOptions: ServeTaskOptions) {
if (commandOptions.environment === '') {
if (commandOptions.target === 'development') {
commandOptions.environment = 'dev';
}
if (commandOptions.target === 'production') {
commandOptions.environment = 'prod';
}
}

// default to extractCss to true on prod target
if (typeof commandOptions.extractCss === 'undefined') {
commandOptions.extractCss = commandOptions.target === 'production';
}

// Check angular version.
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;

return checkExpressPort(commandOptions)
.then(() => autoFindLiveReloadPort(commandOptions))
.then((opts: ServeTaskOptions) => {
commandOptions = assign({}, opts, {
baseURL: this.project.config(commandOptions.target).baseURL || '/'
});

const serve = new ServeWebpackTask({
ui: this.ui,
project: this.project,
});

return serve.run(commandOptions);
return serve.run(opts);
});
}

Expand Down
40 changes: 7 additions & 33 deletions packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,35 @@
import { BuildOptions } from '../models/webpack-config';
import { BaseBuildCommandOptions } from './build';

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

PortFinder.basePort = 49152;

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

export interface ServeTaskOptions {
export interface ServeTaskOptions extends BuildOptions {
port?: number;
host?: string;
proxyConfig?: string;
watcher?: string;
liveReload?: boolean;
liveReloadHost?: string;
liveReloadPort?: number;
liveReloadBaseUrl?: string;
liveReloadLiveCss?: boolean;
target?: string;
environment?: string;
ssl?: boolean;
sslKey?: string;
sslCert?: string;
aot?: boolean;
sourcemap?: boolean;
verbose?: boolean;
progress?: boolean;
open?: boolean;
vendorChunk?: boolean;
hmr?: boolean;
i18nFile?: string;
i18nFormat?: string;
locale?: string;
extractCss?: boolean | null;
}

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

availableOptions: [
availableOptions: BaseBuildCommandOptions.concat([
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
{
name: 'host',
Expand All @@ -48,7 +39,6 @@ const ServeCommand = Command.extend({
description: 'Listens only on localhost by default'
},
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
{
name: 'live-reload-host',
Expand All @@ -74,21 +64,9 @@ const ServeCommand = Command.extend({
default: true,
description: 'Whether to live reload CSS (default true)'
},
{
name: 'target',
type: String,
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
},
{ name: 'environment', type: String, default: '', aliases: ['e'] },
{ name: 'ssl', type: Boolean, default: false },
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
{ name: 'aot', type: Boolean, default: false },
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
{ name: 'vendor-chunk', type: Boolean, default: true },
{ name: 'verbose', type: Boolean, default: false },
{ name: 'progress', type: Boolean, default: true },
{
name: 'open',
type: Boolean,
Expand All @@ -101,12 +79,8 @@ const ServeCommand = Command.extend({
type: Boolean,
default: false,
description: 'Enable hot module replacement',
},
{ name: 'i18n-file', type: String, default: null },
{ name: 'i18n-format', type: String, default: null },
{ name: 'locale', type: String, default: null },
{ name: 'extract-css', type: Boolean, default: null }
],
}
]),

run: function(commandOptions: ServeTaskOptions) {
return require('./serve.run').default.call(this, commandOptions);
Expand Down
5 changes: 0 additions & 5 deletions packages/angular-cli/models/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/angular-cli/models/webpack-build-development.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/angular-cli/models/webpack-build-production.ts

This file was deleted.

Loading

0 comments on commit dedf216

Please sign in to comment.