diff --git a/packages/create-nx-workspace/bin/output.ts b/packages/create-nx-workspace/bin/output.ts index 0a9b4dde8c86e..8e79887e18740 100644 --- a/packages/create-nx-workspace/bin/output.ts +++ b/packages/create-nx-workspace/bin/output.ts @@ -1,7 +1,29 @@ +/* + * Because we don't want to depend on @nrwl/workspace (to speed up the workspace creation) + * we duplicate the helper functions from @nrwl/workspace in this file. + */ + import * as chalk from 'chalk'; import { EOL } from 'os'; -import { isCI } from './is-ci'; -import { TaskStatus } from '../tasks-runner/tasks-runner'; + +export function isCI() { + return ( + process.env.CI === 'true' || + process.env.TF_BUILD === 'true' || + process.env['bamboo.buildKey'] || + process.env.BUILDKITE === 'true' || + process.env.CIRCLECI === 'true' || + process.env.CIRRUS_CI === 'true' || + process.env.CODEBUILD_BUILD_ID || + process.env.GITHUB_ACTIONS === 'true' || + process.env.GITLAB_CI || + process.env.HEROKU_TEST_RUN_ID || + process.env.BUILD_ID || + process.env.BUILD_BUILDID || + process.env.TEAMCITY_VERSION || + process.env.TRAVIS === 'true' + ); +} export interface CLIErrorMessageConfig { title: string; @@ -28,15 +50,12 @@ export interface CLISuccessMessageConfig { /** * Automatically disable styling applied by chalk if CI=true */ -const forceColor = - process.env.FORCE_COLOR === '' || process.env.FORCE_COLOR === 'true'; -if (isCI() && !forceColor) { +if (isCI()) { (chalk as any).level = 0; } class CLIOutput { readonly X_PADDING = ' '; - cliName = 'NX'; /** * Longer dash character which forms more of a continuous line when place side to side @@ -96,12 +115,12 @@ class CLIOutput { let nxPrefix = ''; if (chalk[color]) { nxPrefix = `${chalk[color]('>')} ${chalk.reset.inverse.bold[color]( - ` ${this.cliName} ` + ' NX ' )}`; } else { nxPrefix = `${chalk.keyword(color)( '>' - )} ${chalk.reset.inverse.bold.keyword(color)(` ${this.cliName} `)}`; + )} ${chalk.reset.inverse.bold.keyword(color)(' NX ')}`; } return `${nxPrefix} ${text}`; } @@ -209,28 +228,7 @@ class CLIOutput { this.addNewline(); } - logCommand(message: string, taskStatus?: TaskStatus) { - // normalize the message - if (message.startsWith('nx run ')) { - message = message.substring('nx run '.length); - } else if (message.startsWith('run ')) { - message = message.substring('run '.length); - } - - this.addNewline(); - let commandOutput = `${chalk.dim('> nx run')} ${message}`; - if (taskStatus === 'local-cache') { - commandOutput += ` ${chalk.dim('[local cache]')}`; - } else if (taskStatus === 'remote-cache') { - commandOutput += ` ${chalk.dim('[remote cache]')}`; - } else if (taskStatus === 'local-cache-kept-existing') { - commandOutput += ` ${chalk.dim( - '[existing outputs match the cache, left as is]' - )}`; - } - this.writeToStdOut(commandOutput); - this.addNewline(); - } + logCommand(message: string) {} log({ title, bodyLines, color }: CLIWarnMessageConfig & { color?: string }) { this.addNewline(); diff --git a/packages/nx/src/utils/output.ts b/packages/nx/src/utils/output.ts index 0a9b4dde8c86e..41ce1f8d8c65c 100644 --- a/packages/nx/src/utils/output.ts +++ b/packages/nx/src/utils/output.ts @@ -37,6 +37,7 @@ if (isCI() && !forceColor) { class CLIOutput { readonly X_PADDING = ' '; cliName = 'NX'; + formatCommand = (message: string) => `${chalk.dim('> nx run')} ${message}`; /** * Longer dash character which forms more of a continuous line when place side to side @@ -210,26 +211,47 @@ class CLIOutput { } logCommand(message: string, taskStatus?: TaskStatus) { - // normalize the message + this.addNewline(); + const commandOutput = this.formatCommand(this.normalizeMessage(message)); + const commandOutputWithStatus = this.addTaskStatus( + taskStatus, + commandOutput + ); + this.writeToStdOut(commandOutputWithStatus); + this.addNewline(); + } + + private normalizeMessage(message: string) { if (message.startsWith('nx run ')) { - message = message.substring('nx run '.length); + return message.substring('nx run '.length); } else if (message.startsWith('run ')) { - message = message.substring('run '.length); + return message.substring('run '.length); + } else { + return message; } + } - this.addNewline(); - let commandOutput = `${chalk.dim('> nx run')} ${message}`; + private addTaskStatus( + taskStatus: + | 'success' + | 'failure' + | 'skipped' + | 'local-cache-kept-existing' + | 'local-cache' + | 'remote-cache', + commandOutput: string + ) { if (taskStatus === 'local-cache') { - commandOutput += ` ${chalk.dim('[local cache]')}`; + return `${commandOutput} ${chalk.dim('[local cache]')}`; } else if (taskStatus === 'remote-cache') { - commandOutput += ` ${chalk.dim('[remote cache]')}`; + return `${commandOutput} ${chalk.dim('[remote cache]')}`; } else if (taskStatus === 'local-cache-kept-existing') { - commandOutput += ` ${chalk.dim( + return `${commandOutput} ${chalk.dim( '[existing outputs match the cache, left as is]' )}`; + } else { + return commandOutput; } - this.writeToStdOut(commandOutput); - this.addNewline(); } log({ title, bodyLines, color }: CLIWarnMessageConfig & { color?: string }) {