Skip to content

Commit

Permalink
fix(@angular/cli): show warnings on serve
Browse files Browse the repository at this point in the history
Errors and warnings neet to be printed separately.

Followup to #6989
Fix #7213
  • Loading branch information
filipesilva authored and hansl committed Aug 3, 2017
1 parent 90a14d5 commit ca98b2b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
9 changes: 8 additions & 1 deletion packages/@angular/cli/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BuildTaskOptions } from '../commands/build';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { getWebpackStatsConfig } from '../models/webpack-configs/utils';
import { CliConfig } from '../models/config';
import {statsToString} from '../utilities/stats';
import { statsToString, statsWarningsToString, statsErrorsToString } from '../utilities/stats';

const Task = require('../ember-cli/lib/models/task');
const SilentError = require('silent-error');
Expand Down Expand Up @@ -47,6 +47,13 @@ export default Task.extend({
this.ui.writeLine(statsToString(json, statsConfig));
}

if (stats.hasWarnings()) {
this.ui.writeLine(statsWarningsToString(json, statsConfig));
}
if (stats.hasErrors()) {
this.ui.writeError(statsErrorsToString(json, statsConfig));
}

if (runTaskOptions.watch) {
return;
} else if (runTaskOptions.statsJson) {
Expand Down
14 changes: 7 additions & 7 deletions packages/@angular/cli/tasks/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
import { ServeTaskOptions } from '../commands/serve';
import { CliConfig } from '../models/config';
import { getAppFromConfig } from '../utilities/app-utils';
import {statsToString} from '../utilities/stats';
import { statsToString, statsWarningsToString, statsErrorsToString } from '../utilities/stats';

const WebpackDevServer = require('webpack-dev-server');
const Task = require('../ember-cli/lib/models/task');
Expand Down Expand Up @@ -215,13 +215,13 @@ export default Task.extend({
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
if (!serveTaskOptions.verbose) {
webpackCompiler.plugin('done', (stats: any) => {
const str = statsToString(stats.toJson(), statsConfig);
const json = stats.toJson('verbose');
this.ui.writeLine(statsToString(json, statsConfig));
if (stats.hasWarnings()) {
this.ui.writeLine(statsWarningsToString(json, statsConfig));
}
if (stats.hasErrors()) {
this.ui.writeError(str);
} else if (stats.hasWarnings()) {
this.ui.writeWarnLine(str);
} else {
this.ui.writeLine(str);
this.ui.writeError(statsErrorsToString(json, statsConfig));
}
});
}
Expand Down
25 changes: 19 additions & 6 deletions packages/@angular/cli/utilities/stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold, green, reset, white, yellow } from 'chalk';
import { bold, green, red, reset, white, yellow } from 'chalk';
import { stripIndents } from 'common-tags';


Expand All @@ -16,12 +16,12 @@ function _formatSize(size: number): string {

export function statsToString(json: any, statsConfig: any) {
const colors = statsConfig.colors;
const r = (x: string) => colors ? reset(x) : x;
const rs = (x: string) => colors ? reset(x) : x;
const w = (x: string) => colors ? bold(white(x)) : x;
const g = (x: string) => colors ? bold(green(x)) : x;
const y = (x: string) => colors ? bold(yellow(x)) : x;

return r(stripIndents`
return rs(stripIndents`
Date: ${w(new Date().toISOString())}
Hash: ${w(json.hash)}
Time: ${w('' + json.time)}ms
Expand All @@ -38,8 +38,21 @@ export function statsToString(json: any, statsConfig: any) {
return `chunk {${y(chunk.id)}} ${g(files)}${names}${size}${parents} ${initial}${flags}`;
}).join('\n')}
${json.warnings.map((warning: any) => y(`WARNING in ${warning}`)).join('\n\n')}
${json.errors.map((error: any) => r(`ERROR in ${error}`)).join('\n')}
`);
}

export function statsWarningsToString(json: any, statsConfig: any) {
const colors = statsConfig.colors;
const rs = (x: string) => colors ? reset(x) : x;
const y = (x: string) => colors ? bold(yellow(x)) : x;

return rs('\n' + json.warnings.map((warning: any) => y(`WARNING in ${warning}`)).join('\n\n'));
}

export function statsErrorsToString(json: any, statsConfig: any) {
const colors = statsConfig.colors;
const rs = (x: string) => colors ? reset(x) : x;
const r = (x: string) => colors ? bold(red(x)) : x;

return rs('\n' + json.errors.map((error: any) => r(`ERROR in ${error}`)).join('\n'));
}

0 comments on commit ca98b2b

Please sign in to comment.