Skip to content

Commit f29cb3b

Browse files
committed
refactor(@angular-devkit/architect): use custom indent logger
Replaces `createConsoleLogger` with a custom `logging.IndentLogger` implementation to remove dependency on `@angular-devkit/core/node` helper.
1 parent 240936d commit f29cb3b

1 file changed

Lines changed: 28 additions & 5 deletions

File tree

packages/angular_devkit/architect/bin/architect.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { JsonValue, json, logging, schema, strings, tags, workspaces } from '@angular-devkit/core';
11-
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
11+
import { NodeJsSyncHost } from '@angular-devkit/core/node';
1212
import { existsSync } from 'node:fs';
1313
import * as path from 'node:path';
1414
import { parseArgs, styleText } from 'node:util';
@@ -217,12 +217,35 @@ async function main(args: string[]): Promise<number> {
217217
const { positionals, cliOptions, builderOptions } = parseOptions(args);
218218

219219
/** Create the DevKit Logger used through the CLI. */
220-
const logger = createConsoleLogger(!!cliOptions['verbose'], process.stdout, process.stderr, {
220+
const logger = new logging.IndentLogger('architect');
221+
const colorLevels: Record<string, (message: string) => string> = {
221222
info: (s) => s,
222223
debug: (s) => s,
223-
warn: (s) => styleText(['yellow', 'bold'], s),
224-
error: (s) => styleText(['red', 'bold'], s),
225-
fatal: (s) => styleText(['red', 'bold'], s),
224+
warn: (s) => styleText(['yellow', 'bold'], s, { stream: process.stderr }),
225+
error: (s) => styleText(['red', 'bold'], s, { stream: process.stderr }),
226+
fatal: (s) => styleText(['red', 'bold'], s, { stream: process.stderr }),
227+
};
228+
229+
logger.subscribe((entry) => {
230+
if (entry.level === 'debug' && !cliOptions['verbose']) {
231+
return;
232+
}
233+
234+
const color = colorLevels[entry.level];
235+
const message = color ? color(entry.message) : entry.message;
236+
237+
switch (entry.level) {
238+
case 'warn':
239+
case 'fatal':
240+
case 'error':
241+
// eslint-disable-next-line no-console
242+
console.error(message);
243+
break;
244+
default:
245+
// eslint-disable-next-line no-console
246+
console.log(message);
247+
break;
248+
}
226249
});
227250

228251
// Check the target.

0 commit comments

Comments
 (0)