diff --git a/dev-infra/format/format.ts b/dev-infra/format/format.ts index 03f880134c..c67c50547a 100644 --- a/dev-infra/format/format.ts +++ b/dev-infra/format/format.ts @@ -7,6 +7,9 @@ */ import {prompt} from 'inquirer'; + +import {error, info} from '../utils/console'; + import {runFormatterInParallel} from './run-commands-parallel'; /** @@ -17,16 +20,16 @@ export async function formatFiles(files: string[]) { let failures = await runFormatterInParallel(files, 'format'); if (failures === false) { - console.info('No files matched for formatting.'); + info('No files matched for formatting.'); process.exit(0); } // The process should exit as a failure if any of the files failed to format. if (failures.length !== 0) { - console.error(`Formatting failed, see errors above for more information.`); + error(`Formatting failed, see errors above for more information.`); process.exit(1); } - console.info(`√ Formatting complete.`); + info(`√ Formatting complete.`); process.exit(0); } @@ -38,18 +41,18 @@ export async function checkFiles(files: string[]) { const failures = await runFormatterInParallel(files, 'check'); if (failures === false) { - console.info('No files matched for formatting check.'); + info('No files matched for formatting check.'); process.exit(0); } if (failures.length) { // Provide output expressing which files are failing formatting. - console.group('\nThe following files are out of format:'); + info.group('\nThe following files are out of format:'); for (const file of failures) { - console.info(` - ${file}`); + info(` - ${file}`); } - console.groupEnd(); - console.info(); + info.groupEnd(); + info(); // If the command is run in a non-CI environment, prompt to format the files immediately. let runFormatter = false; @@ -67,13 +70,13 @@ export async function checkFiles(files: string[]) { process.exit(0); } else { // Inform user how to format files in the future. - console.info(); - console.info(`To format the failing file run the following command:`); - console.info(` yarn ng-dev format files ${failures.join(' ')}`); + info(); + info(`To format the failing file run the following command:`); + info(` yarn ng-dev format files ${failures.join(' ')}`); process.exit(1); } } else { - console.info('√ All files correctly formatted.'); + info('√ All files correctly formatted.'); process.exit(0); } } diff --git a/dev-infra/format/formatters/buildifier.ts b/dev-infra/format/formatters/buildifier.ts index 797920030f..8fecfd2c6e 100644 --- a/dev-infra/format/formatters/buildifier.ts +++ b/dev-infra/format/formatters/buildifier.ts @@ -9,6 +9,7 @@ import {join} from 'path'; import {getRepoBaseDir} from '../../utils/config'; +import {error} from '../../utils/console'; import {Formatter} from './base-formatter'; @@ -35,9 +36,9 @@ export class Buildifier extends Formatter { callback: (file: string, code: number, _: string, stderr: string) => { if (code !== 0) { - console.error(`Error running buildifier on: ${file}`); - console.error(stderr); - console.error(); + error(`Error running buildifier on: ${file}`); + error(stderr); + error(); return true; } return false; diff --git a/dev-infra/format/formatters/clang-format.ts b/dev-infra/format/formatters/clang-format.ts index c3aedad384..3c33b3d28b 100644 --- a/dev-infra/format/formatters/clang-format.ts +++ b/dev-infra/format/formatters/clang-format.ts @@ -9,6 +9,7 @@ import {join} from 'path'; import {getRepoBaseDir} from '../../utils/config'; +import {error} from '../../utils/console'; import {Formatter} from './base-formatter'; @@ -35,9 +36,9 @@ export class ClangFormat extends Formatter { callback: (file: string, code: number, _: string, stderr: string) => { if (code !== 0) { - console.error(`Error running clang-format on: ${file}`); - console.error(stderr); - console.error(); + error(`Error running clang-format on: ${file}`); + error(stderr); + error(); return true; } return false; diff --git a/dev-infra/format/run-commands-parallel.ts b/dev-infra/format/run-commands-parallel.ts index b2f86cb60e..5b03c7bcc2 100644 --- a/dev-infra/format/run-commands-parallel.ts +++ b/dev-infra/format/run-commands-parallel.ts @@ -11,6 +11,8 @@ import * as multimatch from 'multimatch'; import {cpus} from 'os'; import {exec} from 'shelljs'; +import {info} from '../utils/console'; + import {Formatter, FormatterAction, getActiveFormatters} from './formatters'; const AVAILABLE_THREADS = Math.max(cpus().length - 1, 1); @@ -47,10 +49,10 @@ export function runFormatterInParallel(allFiles: string[], action: FormatterActi switch (action) { case 'format': - console.info(`Formatting ${pendingCommands.length} file(s)`); + info(`Formatting ${pendingCommands.length} file(s)`); break; case 'check': - console.info(`Checking format of ${pendingCommands.length} file(s)`); + info(`Checking format of ${pendingCommands.length} file(s)`); break; default: throw Error(`Invalid format action "${action}": allowed actions are "format" and "check"`);