Skip to content

Commit 6afa952

Browse files
Broccohansl
authored andcommitted
fix(@angular/cli): Pass logger to allow schematics to log messages
fixes #9976
1 parent 40dfce9 commit 6afa952

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

packages/@angular/cli/commands/generate.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import chalk from 'chalk';
22
const stringUtils = require('ember-cli-string-utils');
33
import { oneLine } from 'common-tags';
44
import { CliConfig } from '../models/config';
5+
import { logging, terminal } from '@angular-devkit/core';
6+
import { filter } from 'rxjs/operators';
57

68
import {
79
getCollection,
@@ -199,12 +201,40 @@ export default Command.extend({
199201
commandOptions.type = rawArgs[2];
200202
}
201203

204+
const logger = new logging.IndentLogger('cling');
205+
const loggerSubscription = logger.pipe(
206+
filter(entry => (entry.level != 'debug')))
207+
.subscribe(entry => {
208+
let color = (x: any) => terminal.dim(terminal.white(x));
209+
let output = process.stdout;
210+
switch (entry.level) {
211+
case 'info':
212+
color = terminal.white;
213+
break;
214+
case 'warn':
215+
color = terminal.yellow;
216+
break;
217+
case 'error':
218+
color = terminal.red;
219+
output = process.stderr;
220+
break;
221+
case 'fatal':
222+
color = (x) => terminal.bold(terminal.red(x));
223+
output = process.stderr;
224+
break;
225+
}
226+
227+
output.write(color(entry.message) + '\n');
228+
});
229+
202230
return schematicRunTask.run({
203231
taskOptions: commandOptions,
204232
workingDir: cwd,
205233
collectionName,
206-
schematicName
207-
});
234+
schematicName,
235+
logger: this.logger
236+
})
237+
.then(() => loggerSubscription.unsubscribe());
208238
},
209239

210240
printDetailedHelp: function (_options: any, rawArgs: any): string | Promise<string> {

packages/@angular/cli/tasks/schematic-run.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import chalk from 'chalk';
1515
import { CliConfig } from '../models/config';
1616
import { concat, concatMap, ignoreElements, map } from 'rxjs/operators';
1717
import { getCollection, getSchematic, getEngineHost, getEngine } from '../utilities/schematics';
18+
import { logging } from '@angular-devkit/core';
1819

1920
const { green, red, yellow } = chalk;
2021
const Task = require('../ember-cli/lib/models/task');
@@ -25,6 +26,7 @@ export interface SchematicRunOptions {
2526
emptyHost: boolean;
2627
collectionName: string;
2728
schematicName: string;
29+
logger: logging.Logger;
2830
}
2931

3032
export interface SchematicOptions {
@@ -45,7 +47,7 @@ interface OutputLogging {
4547

4648
export default Task.extend({
4749
run: function (options: SchematicRunOptions): Promise<SchematicOutput> {
48-
const { taskOptions, workingDir, emptyHost, collectionName, schematicName } = options;
50+
const { taskOptions, workingDir, emptyHost, collectionName, schematicName, logger } = options;
4951

5052
const ui = this.ui;
5153

@@ -125,7 +127,7 @@ export default Task.extend({
125127
});
126128

127129
return new Promise((resolve, reject) => {
128-
schematic.call(opts, host).pipe(
130+
schematic.call(opts, host, { logger }).pipe(
129131
map((tree: Tree) => Tree.optimize(tree)),
130132
concatMap((tree: Tree) => {
131133
return dryRunSink.commit(tree).pipe(

0 commit comments

Comments
 (0)