Skip to content

Commit

Permalink
feat(build): add --verbose flag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
filipesilva committed Oct 27, 2016
1 parent 86021a0 commit c06b3b2
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 49 deletions.
4 changes: 3 additions & 1 deletion packages/angular-cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface BuildOptions {
supressSizes: boolean;
baseHref?: string;
aot?: boolean;
verbose?: boolean;
}

const BuildCommand = Command.extend({
Expand All @@ -31,7 +32,8 @@ const BuildCommand = Command.extend({
{ 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: 'aot', type: Boolean, default: false },
{ name: 'verbose', type: Boolean, default: false }
],

run: function (commandOptions: BuildOptions) {
Expand Down
2 changes: 2 additions & 0 deletions packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ServeTaskOptions {
sslKey?: string;
sslCert?: string;
aot?: boolean;
verbose?: boolean;
open?: boolean;
}

Expand Down Expand Up @@ -81,6 +82,7 @@ const ServeCommand = Command.extend({
{ 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: 'verbose', type: Boolean, default: false },
{
name: 'open',
type: Boolean,
Expand Down
6 changes: 4 additions & 2 deletions packages/angular-cli/models/webpack-build-production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ declare module 'webpack' {
}
}

export const getWebpackProdConfigPartial = function(projectRoot: string, appConfig: any) {
export const getWebpackProdConfigPartial = function(projectRoot: string,
appConfig: any,
verbose: any) {
return {
devtool: 'source-map',
output: {
Expand All @@ -29,7 +31,7 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
}),
new webpack.optimize.UglifyJsPlugin(<any>{
mangle: { screw_ie8 : true },
compress: { screw_ie8: true },
compress: { screw_ie8: true, warnings: verbose },
sourceMap: true
}),
new CompressionPlugin({
Expand Down
18 changes: 11 additions & 7 deletions packages/angular-cli/models/webpack-build-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ export const ngAppResolve = (resolvePath: string): string => {

export const webpackOutputOptions = {
colors: true,
hash: true,
timings: true,
chunks: true,
chunkModules: false,
children: false, // listing all children is very noisy in AOT and hides warnings/errors
modules: false,
reasons: false,
chunkModules: false
warnings: true,
assets: false, // listing all assets is very noisy when using assets directories
version: false
};

export const webpackDevServerOutputOptions = {
export const verboseWebpackOutputOptions = {
children: true,
assets: true,
colors: true,
version: true,
hash: true,
timings: true,
chunks: false,
chunkModules: false
reasons: true,
chunkModules: false // TODO: set to true when console to file output is fixed
};
9 changes: 5 additions & 4 deletions packages/angular-cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class NgCliWebpackConfig {
public environment: string,
outputDir?: string,
baseHref?: string,
isAoT = false
isAoT = false,
verbose = false
) {
const config: CliConfig = CliConfig.fromProject();
const appConfig = config.config.apps[0];
Expand All @@ -36,7 +37,7 @@ export class NgCliWebpackConfig {
appConfig,
baseHref
);
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig);
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig, verbose);
const typescriptConfigPartial = isAoT
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig)
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
Expand All @@ -58,12 +59,12 @@ export class NgCliWebpackConfig {
);
}

getTargetConfig(projectRoot: string, appConfig: any): any {
getTargetConfig(projectRoot: string, appConfig: any, verbose: boolean): any {
switch (this.target) {
case 'development':
return getWebpackDevConfigPartial(projectRoot, appConfig);
case 'production':
return getWebpackProdConfigPartial(projectRoot, appConfig);
return getWebpackProdConfigPartial(projectRoot, appConfig, verbose);
default:
throw new Error("Invalid build target. Only 'development' and 'production' are available.");
}
Expand Down
20 changes: 14 additions & 6 deletions packages/angular-cli/tasks/build-webpack-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Task = require('ember-cli/lib/models/task');
import * as webpack from 'webpack';
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
import { NgCliWebpackConfig } from '../models/webpack-config';
import { webpackOutputOptions } from '../models/';
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
import { BuildOptions } from '../commands/build';
import { CliConfig } from '../models/config';

Expand All @@ -24,13 +24,21 @@ export default Task.extend({
runTaskOptions.environment,
outputDir,
runTaskOptions.baseHref,
runTaskOptions.aot
runTaskOptions.aot,
runTaskOptions.verbose
).config;
const webpackCompiler: any = webpack(config);

webpackCompiler.apply(new ProgressPlugin({
profile: true
}));
const statsOptions = runTaskOptions.verbose
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
: webpackOutputOptions;

if (runTaskOptions.verbose) {
webpackCompiler.apply(new ProgressPlugin({
profile: runTaskOptions.verbose,
colors: true
}));
}

return new Promise((resolve, reject) => {
webpackCompiler.watch({}, (err: any, stats: any) => {
Expand All @@ -43,7 +51,7 @@ export default Task.extend({

if (stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(webpackOutputOptions) + '\n');
process.stdout.write(stats.toString(statsOptions) + '\n');
}
});
});
Expand Down
23 changes: 15 additions & 8 deletions packages/angular-cli/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as rimraf from 'rimraf';
import * as path from 'path';
const Task = require('ember-cli/lib/models/task');
import * as webpack from 'webpack';
const Task = require('ember-cli/lib/models/task');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
import { BuildOptions } from '../commands/build';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { webpackOutputOptions } from '../models/';
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
import { CliConfig } from '../models/config';

// Configure build and output;
Expand All @@ -23,19 +24,25 @@ export default <any>Task.extend({
runTaskOptions.environment,
outputDir,
runTaskOptions.baseHref,
runTaskOptions.aot
runTaskOptions.aot,
runTaskOptions.verbose
).config;

// fail on build error
config.bail = true;

const webpackCompiler: any = webpack(config);

const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const statsOptions = runTaskOptions.verbose
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
: webpackOutputOptions;

webpackCompiler.apply(new ProgressPlugin({
profile: true
}));
if (runTaskOptions.verbose) {
webpackCompiler.apply(new ProgressPlugin({
profile: runTaskOptions.verbose,
colors: true
}));
}

return new Promise((resolve, reject) => {
webpackCompiler.run((err: any, stats: any) => {
Expand All @@ -51,7 +58,7 @@ export default <any>Task.extend({

if (stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(webpackOutputOptions) + '\n');
process.stdout.write(stats.toString(statsOptions) + '\n');
}
resolve();
});
Expand Down
51 changes: 30 additions & 21 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Task = require('ember-cli/lib/models/task');
import * as webpack from 'webpack';
const WebpackDevServer = require('webpack-dev-server');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
import { webpackDevServerOutputOptions } from '../models/';
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { ServeTaskOptions } from '../commands/serve';
import { CliConfig } from '../models/config';
Expand All @@ -15,35 +15,42 @@ import * as url from 'url';
const opn = require('opn');

export default Task.extend({
run: function(commandOptions: ServeTaskOptions) {
run: function(serveTaskOptions: ServeTaskOptions) {
const ui = this.ui;

let webpackCompiler: any;

let config = new NgCliWebpackConfig(
this.project,
commandOptions.target,
commandOptions.environment,
serveTaskOptions.target,
serveTaskOptions.environment,
undefined,
undefined,
commandOptions.aot
serveTaskOptions.aot,
serveTaskOptions.verbose
).config;

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

webpackCompiler.apply(new ProgressPlugin({
profile: true,
colors: true
}));
const statsOptions = serveTaskOptions.verbose
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
: webpackOutputOptions;

if (serveTaskOptions.verbose) {
webpackCompiler.apply(new ProgressPlugin({
profile: serveTaskOptions.verbose,
colors: true
}));
}

let proxyConfig = {};
if (commandOptions.proxyConfig) {
const proxyPath = path.resolve(this.project.root, commandOptions.proxyConfig);
if (serveTaskOptions.proxyConfig) {
const proxyPath = path.resolve(this.project.root, serveTaskOptions.proxyConfig);
if (fs.existsSync(proxyPath)) {
proxyConfig = require(proxyPath);
} else {
Expand All @@ -54,12 +61,12 @@ export default Task.extend({

let sslKey: string = null;
let sslCert: string = null;
if (commandOptions.ssl) {
const keyPath = path.resolve(this.project.root, commandOptions.sslKey);
if (serveTaskOptions.ssl) {
const keyPath = path.resolve(this.project.root, serveTaskOptions.sslKey);
if (fs.existsSync(keyPath)) {
sslKey = fs.readFileSync(keyPath, 'utf-8');
}
const certPath = path.resolve(this.project.root, commandOptions.sslCert);
const certPath = path.resolve(this.project.root, serveTaskOptions.sslCert);
if (fs.existsSync(certPath)) {
sslCert = fs.readFileSync(certPath, 'utf-8');
}
Expand All @@ -73,14 +80,14 @@ export default Task.extend({
historyApiFallback: {
disableDotRule: true,
},
stats: webpackDevServerOutputOptions,
stats: statsOptions,
inline: true,
proxy: proxyConfig,
compress: commandOptions.target === 'production',
compress: serveTaskOptions.target === 'production',
watchOptions: {
poll: CliConfig.fromProject().config.defaults.poll
},
https: commandOptions.ssl
https: serveTaskOptions.ssl
};

if (sslKey != null && sslCert != null) {
Expand All @@ -91,19 +98,21 @@ export default Task.extend({
ui.writeLine(chalk.green(oneLine`
**
NG Live Development Server is running on
http${commandOptions.ssl ? 's' : ''}://${commandOptions.host}:${commandOptions.port}.
http${serveTaskOptions.ssl ? 's' : ''}://${serveTaskOptions.host}:${serveTaskOptions.port}.
**
`));

const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
return new Promise((resolve, reject) => {
server.listen(commandOptions.port, `${commandOptions.host}`, function(err: any, stats: any) {
server.listen(serveTaskOptions.port,
`${serveTaskOptions.host}`,
function(err: any, stats: any) {
if (err) {
console.error(err.stack || err);
if (err.details) { console.error(err.details); }
reject(err.details);
} else {
const { open, host, port } = commandOptions;
const { open, host, port } = serveTaskOptions;
if (open) {
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() }));
}
Expand Down

0 comments on commit c06b3b2

Please sign in to comment.