Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/angular/cli/lib/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { createConsoleLogger } from '@angular-devkit/core/node';
import { format } from 'util';
import { runCommand } from '../../models/command-runner';
import { colors, supportsColor } from '../../utilities/color';
import { colors, removeColor, supportsColor } from '../../utilities/color';
import { getWorkspaceRaw } from '../../utilities/config';
import { writeErrorToLogFile } from '../../utilities/log-file';
import { getWorkspaceDetails } from '../../utilities/project';
Expand All @@ -34,11 +34,11 @@ export default async function(options: { testing?: boolean; cliArgs: string[] })
}

const logger = createConsoleLogger(isDebug, process.stdout, process.stderr, {
info: s => (supportsColor ? s : colors.unstyle(s)),
debug: s => (supportsColor ? s : colors.unstyle(s)),
warn: s => (supportsColor ? colors.bold.yellow(s) : colors.unstyle(s)),
error: s => (supportsColor ? colors.bold.red(s) : colors.unstyle(s)),
fatal: s => (supportsColor ? colors.bold.red(s) : colors.unstyle(s)),
info: s => (supportsColor ? s : removeColor(s)),
debug: s => (supportsColor ? s : removeColor(s)),
warn: s => (supportsColor ? colors.bold.yellow(s) : removeColor(s)),
error: s => (supportsColor ? colors.bold.red(s) : removeColor(s)),
fatal: s => (supportsColor ? colors.bold.red(s) : removeColor(s)),
});

// Redirect console to logger
Expand Down
10 changes: 8 additions & 2 deletions packages/angular/cli/utilities/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as colors from 'ansi-colors';
import * as ansiColors from 'ansi-colors';
import { WriteStream } from 'tty';

// Typings do not contain the function call (added in Node.js v9.9.0)
export const supportsColor =
process.stdout instanceof WriteStream &&
((process.stdout as unknown) as { getColorDepth(): number }).getColorDepth() > 1;

(colors as { enabled: boolean }).enabled = supportsColor;
export function removeColor(text: string): string {
return text.replace(new RegExp(ansiColors.ansiRegex), '');
}

// tslint:disable-next-line: no-any
const colors = (ansiColors as any).create() as typeof ansiColors;
colors.enabled = supportsColor;

export { colors };