Skip to content

Commit

Permalink
fix(@angular/cli): Pass logger to allow schematics to log messages
Browse files Browse the repository at this point in the history
fixes #9976
  • Loading branch information
Brocco authored and hansl committed Mar 15, 2018
1 parent 40dfce9 commit 6afa952
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
34 changes: 32 additions & 2 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import chalk from 'chalk';
const stringUtils = require('ember-cli-string-utils');
import { oneLine } from 'common-tags';
import { CliConfig } from '../models/config';
import { logging, terminal } from '@angular-devkit/core';
import { filter } from 'rxjs/operators';

import {
getCollection,
Expand Down Expand Up @@ -199,12 +201,40 @@ export default Command.extend({
commandOptions.type = rawArgs[2];
}

const logger = new logging.IndentLogger('cling');
const loggerSubscription = logger.pipe(
filter(entry => (entry.level != 'debug')))
.subscribe(entry => {
let color = (x: any) => terminal.dim(terminal.white(x));
let output = process.stdout;
switch (entry.level) {
case 'info':
color = terminal.white;
break;
case 'warn':
color = terminal.yellow;
break;
case 'error':
color = terminal.red;
output = process.stderr;
break;
case 'fatal':
color = (x) => terminal.bold(terminal.red(x));
output = process.stderr;
break;
}

output.write(color(entry.message) + '\n');
});

return schematicRunTask.run({
taskOptions: commandOptions,
workingDir: cwd,
collectionName,
schematicName
});
schematicName,
logger: this.logger
})
.then(() => loggerSubscription.unsubscribe());
},

printDetailedHelp: function (_options: any, rawArgs: any): string | Promise<string> {
Expand Down
6 changes: 4 additions & 2 deletions packages/@angular/cli/tasks/schematic-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import chalk from 'chalk';
import { CliConfig } from '../models/config';
import { concat, concatMap, ignoreElements, map } from 'rxjs/operators';
import { getCollection, getSchematic, getEngineHost, getEngine } from '../utilities/schematics';
import { logging } from '@angular-devkit/core';

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

export interface SchematicOptions {
Expand All @@ -45,7 +47,7 @@ interface OutputLogging {

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

const ui = this.ui;

Expand Down Expand Up @@ -125,7 +127,7 @@ export default Task.extend({
});

return new Promise((resolve, reject) => {
schematic.call(opts, host).pipe(
schematic.call(opts, host, { logger }).pipe(
map((tree: Tree) => Tree.optimize(tree)),
concatMap((tree: Tree) => {
return dryRunSink.commit(tree).pipe(
Expand Down

0 comments on commit 6afa952

Please sign in to comment.