Skip to content

Commit 1519b63

Browse files
committed
feat(build): add --verbose and --progress flags
Currently builds output a lot of information, some of which can hide errors, by default. This PR cuts down on the information shown and adds a `--verbose` flag to restore previous build output. A `--progress` flag is also present to turn off progress logging in CI environments. Fix angular#1836 Fix angular#2012
1 parent fe4b35b commit 1519b63

12 files changed

+101
-52
lines changed

packages/angular-cli/commands/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface BuildOptions {
1212
baseHref?: string;
1313
aot?: boolean;
1414
sourcemap?: boolean;
15+
verbose?: boolean;
16+
progress?: boolean;
1517
}
1618

1719
const BuildCommand = Command.extend({
@@ -33,7 +35,9 @@ const BuildCommand = Command.extend({
3335
{ name: 'suppress-sizes', type: Boolean, default: false },
3436
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
3537
{ name: 'aot', type: Boolean, default: false },
36-
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] }
38+
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
39+
{ name: 'verbose', type: Boolean, default: false },
40+
{ name: 'progress', type: Boolean, default: true }
3741
],
3842

3943
run: function (commandOptions: BuildOptions) {

packages/angular-cli/commands/serve.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface ServeTaskOptions {
2727
sslCert?: string;
2828
aot?: boolean;
2929
sourcemap?: boolean;
30+
verbose?: boolean;
31+
progress?: boolean;
3032
open?: boolean;
3133
}
3234

@@ -83,6 +85,8 @@ const ServeCommand = Command.extend({
8385
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
8486
{ name: 'aot', type: Boolean, default: false },
8587
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
88+
{ name: 'verbose', type: Boolean, default: false },
89+
{ name: 'progress', type: Boolean, default: true },
8690
{
8791
name: 'open',
8892
type: Boolean,

packages/angular-cli/commands/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface TestOptions {
1414
reporters?: string;
1515
build?: boolean;
1616
sourcemap?: boolean;
17+
progress?: boolean;
1718
}
1819

1920

@@ -23,6 +24,7 @@ const NgCliTestCommand = TestCommand.extend({
2324
{ name: 'code-coverage', type: Boolean, default: false, aliases: ['cc'] },
2425
{ name: 'lint', type: Boolean, default: false, aliases: ['l'] },
2526
{ name: 'single-run', type: Boolean, default: false, aliases: ['sr'] },
27+
{ name: 'progress', type: Boolean, default: true},
2628
{ name: 'browsers', type: String },
2729
{ name: 'colors', type: Boolean },
2830
{ name: 'log-level', type: String },

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ declare module 'webpack' {
1414
}
1515
}
1616

17-
export const getWebpackProdConfigPartial = function(projectRoot: string, appConfig: any) {
17+
export const getWebpackProdConfigPartial = function(projectRoot: string,
18+
appConfig: any,
19+
verbose: any) {
1820
const appRoot = path.resolve(projectRoot, appConfig.root);
1921
const styles = appConfig.styles
2022
? appConfig.styles.map((style: string) => path.resolve(appRoot, style))
2123
: [];
2224
const cssLoaders = ['css-loader?sourcemap&minimize', 'postcss-loader'];
25+
2326
return {
2427
output: {
2528
path: path.resolve(projectRoot, appConfig.outDir),
@@ -57,7 +60,7 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
5760
}),
5861
new webpack.optimize.UglifyJsPlugin(<any>{
5962
mangle: { screw_ie8 : true },
60-
compress: { screw_ie8: true },
63+
compress: { screw_ie8: true, warnings: verbose },
6164
sourceMap: true
6265
}),
6366
new CompressionPlugin({

packages/angular-cli/models/webpack-build-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const webpackLoader = g['angularCliIsLocal']
1010
? g.angularCliPackages['@ngtools/webpack'].main
1111
: '@ngtools/webpack';
1212

13+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
1314

1415
const getWebpackTestConfig = function (projectRoot, environment, appConfig, testConfig) {
1516

1617
const appRoot = path.resolve(projectRoot, appConfig.root);
17-
const extraRules = [];
18-
const extraPlugins = [];
18+
var extraRules = [];
19+
var extraPlugins = [];
1920

2021
if (testConfig.codeCoverage) {
2122
extraRules.push({
@@ -49,6 +50,10 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test
4950
}))
5051
}
5152

53+
if (testConfig.progress) {
54+
extraPlugins.push(new ProgressPlugin({ colors: true }));
55+
}
56+
5257
return {
5358
devtool: testConfig.sourcemap ? 'inline-source-map' : 'eval',
5459
context: path.resolve(__dirname, './'),

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ export const ngAppResolve = (resolvePath: string): string => {
66

77
export const webpackOutputOptions = {
88
colors: true,
9+
hash: true,
10+
timings: true,
911
chunks: true,
12+
chunkModules: false,
13+
children: false, // listing all children is very noisy in AOT and hides warnings/errors
1014
modules: false,
1115
reasons: false,
12-
chunkModules: false
16+
warnings: true,
17+
assets: false, // listing all assets is very noisy when using assets directories
18+
version: false
1319
};
1420

15-
export const webpackDevServerOutputOptions = {
21+
export const verboseWebpackOutputOptions = {
22+
children: true,
1623
assets: true,
17-
colors: true,
1824
version: true,
19-
hash: true,
20-
timings: true,
21-
chunks: false,
22-
chunkModules: false
25+
reasons: true,
26+
chunkModules: false // TODO: set to true when console to file output is fixed
2327
};

packages/angular-cli/models/webpack-config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class NgCliWebpackConfig {
2525
baseHref?: string,
2626
isAoT = false,
2727
sourcemap = true,
28+
verbose = false
2829
) {
2930
const config: CliConfig = CliConfig.fromProject();
3031
const appConfig = config.config.apps[0];
@@ -38,7 +39,7 @@ export class NgCliWebpackConfig {
3839
baseHref,
3940
sourcemap
4041
);
41-
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig);
42+
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig, verbose);
4243
const typescriptConfigPartial = isAoT
4344
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig)
4445
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
@@ -60,12 +61,12 @@ export class NgCliWebpackConfig {
6061
);
6162
}
6263

63-
getTargetConfig(projectRoot: string, appConfig: any): any {
64+
getTargetConfig(projectRoot: string, appConfig: any, verbose: boolean): any {
6465
switch (this.target) {
6566
case 'development':
6667
return getWebpackDevConfigPartial(projectRoot, appConfig);
6768
case 'production':
68-
return getWebpackProdConfigPartial(projectRoot, appConfig);
69+
return getWebpackProdConfigPartial(projectRoot, appConfig, verbose);
6970
default:
7071
throw new Error("Invalid build target. Only 'development' and 'production' are available.");
7172
}

packages/angular-cli/plugins/karma.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const init = (config) => {
1313
const testConfig = {
1414
codeCoverage: config.angularCli.codeCoverage || false,
1515
lint: config.angularCli.lint || false,
16-
sourcemap: config.angularCli.sourcemap
16+
sourcemap: config.angularCli.sourcemap,
17+
progress: config.angularCli.progress
1718
}
1819

1920
// add webpack config

packages/angular-cli/tasks/build-webpack-watch.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Task = require('../ember-cli/lib/models/task');
44
import * as webpack from 'webpack';
55
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
66
import { NgCliWebpackConfig } from '../models/webpack-config';
7-
import { webpackOutputOptions } from '../models/';
7+
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
88
import { BuildOptions } from '../commands/build';
99
import { CliConfig } from '../models/config';
1010

@@ -25,13 +25,21 @@ export default Task.extend({
2525
outputDir,
2626
runTaskOptions.baseHref,
2727
runTaskOptions.aot,
28-
runTaskOptions.sourcemap
28+
runTaskOptions.sourcemap,
29+
runTaskOptions.verbose,
2930
).config;
3031
const webpackCompiler: any = webpack(config);
3132

32-
webpackCompiler.apply(new ProgressPlugin({
33-
profile: true
34-
}));
33+
const statsOptions = runTaskOptions.verbose
34+
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
35+
: webpackOutputOptions;
36+
37+
if (runTaskOptions.progress) {
38+
webpackCompiler.apply(new ProgressPlugin({
39+
profile: runTaskOptions.verbose,
40+
colors: true
41+
}));
42+
}
3543

3644
return new Promise((resolve, reject) => {
3745
webpackCompiler.watch({}, (err: any, stats: any) => {
@@ -44,7 +52,7 @@ export default Task.extend({
4452

4553
if (stats.hash !== lastHash) {
4654
lastHash = stats.hash;
47-
process.stdout.write(stats.toString(webpackOutputOptions) + '\n');
55+
process.stdout.write(stats.toString(statsOptions) + '\n');
4856
}
4957
});
5058
});

packages/angular-cli/tasks/build-webpack.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as rimraf from 'rimraf';
22
import * as path from 'path';
33
const Task = require('../ember-cli/lib/models/task');
44
import * as webpack from 'webpack';
5+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
56
import { BuildOptions } from '../commands/build';
67
import { NgCliWebpackConfig } from '../models/webpack-config';
7-
import { webpackOutputOptions } from '../models/';
8+
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
89
import { CliConfig } from '../models/config';
910

1011
// Configure build and output;
@@ -24,16 +25,22 @@ export default <any>Task.extend({
2425
outputDir,
2526
runTaskOptions.baseHref,
2627
runTaskOptions.aot,
27-
runTaskOptions.sourcemap
28+
runTaskOptions.sourcemap,
29+
runTaskOptions.verbose
2830
).config;
2931

3032
const webpackCompiler: any = webpack(config);
3133

32-
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
34+
const statsOptions = runTaskOptions.verbose
35+
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
36+
: webpackOutputOptions;
3337

34-
webpackCompiler.apply(new ProgressPlugin({
35-
profile: true
36-
}));
38+
if (runTaskOptions.progress) {
39+
webpackCompiler.apply(new ProgressPlugin({
40+
profile: runTaskOptions.verbose,
41+
colors: true
42+
}));
43+
}
3744

3845
return new Promise((resolve, reject) => {
3946
webpackCompiler.run((err: any, stats: any) => {
@@ -45,7 +52,7 @@ export default <any>Task.extend({
4552

4653
if (stats.hash !== lastHash) {
4754
lastHash = stats.hash;
48-
process.stdout.write(stats.toString(webpackOutputOptions) + '\n');
55+
process.stdout.write(stats.toString(statsOptions) + '\n');
4956
}
5057

5158
return stats.hasErrors() ? reject() : resolve();

packages/angular-cli/tasks/serve-webpack.ts

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Task = require('../ember-cli/lib/models/task');
66
import * as webpack from 'webpack';
77
const WebpackDevServer = require('webpack-dev-server');
88
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
9-
import { webpackDevServerOutputOptions } from '../models/';
9+
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
1010
import { NgCliWebpackConfig } from '../models/webpack-config';
1111
import { ServeTaskOptions } from '../commands/serve';
1212
import { CliConfig } from '../models/config';
@@ -15,36 +15,43 @@ import * as url from 'url';
1515
const opn = require('opn');
1616

1717
export default Task.extend({
18-
run: function(commandOptions: ServeTaskOptions) {
18+
run: function(serveTaskOptions: ServeTaskOptions) {
1919
const ui = this.ui;
2020

2121
let webpackCompiler: any;
2222

2323
let config = new NgCliWebpackConfig(
2424
this.project,
25-
commandOptions.target,
26-
commandOptions.environment,
25+
serveTaskOptions.target,
26+
serveTaskOptions.environment,
2727
undefined,
2828
undefined,
29-
commandOptions.aot,
30-
commandOptions.sourcemap
29+
serveTaskOptions.aot,
30+
serveTaskOptions.sourcemap,
31+
serveTaskOptions.verbose
3132
).config;
3233

3334
// This allows for live reload of page when changes are made to repo.
3435
// https://webpack.github.io/docs/webpack-dev-server.html#inline-mode
3536
config.entry.main.unshift(
36-
`webpack-dev-server/client?http://${commandOptions.host}:${commandOptions.port}/`
37+
`webpack-dev-server/client?http://${serveTaskOptions.host}:${serveTaskOptions.port}/`
3738
);
3839
webpackCompiler = webpack(config);
3940

40-
webpackCompiler.apply(new ProgressPlugin({
41-
profile: true,
42-
colors: true
43-
}));
41+
const statsOptions = serveTaskOptions.verbose
42+
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
43+
: webpackOutputOptions;
44+
45+
if (serveTaskOptions.progress) {
46+
webpackCompiler.apply(new ProgressPlugin({
47+
profile: serveTaskOptions.verbose,
48+
colors: true
49+
}));
50+
}
4451

4552
let proxyConfig = {};
46-
if (commandOptions.proxyConfig) {
47-
const proxyPath = path.resolve(this.project.root, commandOptions.proxyConfig);
53+
if (serveTaskOptions.proxyConfig) {
54+
const proxyPath = path.resolve(this.project.root, serveTaskOptions.proxyConfig);
4855
if (fs.existsSync(proxyPath)) {
4956
proxyConfig = require(proxyPath);
5057
} else {
@@ -55,12 +62,12 @@ export default Task.extend({
5562

5663
let sslKey: string = null;
5764
let sslCert: string = null;
58-
if (commandOptions.ssl) {
59-
const keyPath = path.resolve(this.project.root, commandOptions.sslKey);
65+
if (serveTaskOptions.ssl) {
66+
const keyPath = path.resolve(this.project.root, serveTaskOptions.sslKey);
6067
if (fs.existsSync(keyPath)) {
6168
sslKey = fs.readFileSync(keyPath, 'utf-8');
6269
}
63-
const certPath = path.resolve(this.project.root, commandOptions.sslCert);
70+
const certPath = path.resolve(this.project.root, serveTaskOptions.sslCert);
6471
if (fs.existsSync(certPath)) {
6572
sslCert = fs.readFileSync(certPath, 'utf-8');
6673
}
@@ -76,14 +83,14 @@ export default Task.extend({
7683
disableDotRule: true,
7784
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
7885
},
79-
stats: webpackDevServerOutputOptions,
86+
stats: statsOptions,
8087
inline: true,
8188
proxy: proxyConfig,
82-
compress: commandOptions.target === 'production',
89+
compress: serveTaskOptions.target === 'production',
8390
watchOptions: {
8491
poll: CliConfig.fromProject().config.defaults.poll
8592
},
86-
https: commandOptions.ssl
93+
https: serveTaskOptions.ssl
8794
};
8895

8996
if (sslKey != null && sslCert != null) {
@@ -94,19 +101,21 @@ export default Task.extend({
94101
ui.writeLine(chalk.green(oneLine`
95102
**
96103
NG Live Development Server is running on
97-
http${commandOptions.ssl ? 's' : ''}://${commandOptions.host}:${commandOptions.port}.
104+
http${serveTaskOptions.ssl ? 's' : ''}://${serveTaskOptions.host}:${serveTaskOptions.port}.
98105
**
99106
`));
100107

101108
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
102109
return new Promise((resolve, reject) => {
103-
server.listen(commandOptions.port, `${commandOptions.host}`, function(err: any, stats: any) {
110+
server.listen(serveTaskOptions.port,
111+
`${serveTaskOptions.host}`,
112+
function(err: any, stats: any) {
104113
if (err) {
105114
console.error(err.stack || err);
106115
if (err.details) { console.error(err.details); }
107116
reject(err.details);
108117
} else {
109-
const { open, host, port } = commandOptions;
118+
const { open, host, port } = serveTaskOptions;
110119
if (open) {
111120
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() }));
112121
}

0 commit comments

Comments
 (0)