diff --git a/packages/create-nx-plugin/bin/create-nx-plugin.ts b/packages/create-nx-plugin/bin/create-nx-plugin.ts index b3087ec81eb2c..00ff5a91469d8 100644 --- a/packages/create-nx-plugin/bin/create-nx-plugin.ts +++ b/packages/create-nx-plugin/bin/create-nx-plugin.ts @@ -21,6 +21,12 @@ import { createWorkspace, CreateWorkspaceOptions } from 'create-nx-workspace'; import { output } from 'create-nx-workspace/src/utils/output'; import { CI } from 'create-nx-workspace/src/utils/ci/ci-list'; import type { PackageManager } from 'create-nx-workspace/src/utils/package-manager'; +import { showNxWarning } from 'create-nx-workspace/src/utils/nx/show-nx-warning'; +import { printNxCloudSuccessMessage } from 'create-nx-workspace/src/utils/nx/nx-cloud'; +import { + messages, + recordStat, +} from 'create-nx-workspace/src/utils/nx/ab-testing'; export const yargsDecorator = { 'Options:': `${chalk.green`Options`}:`, @@ -120,7 +126,32 @@ async function main(parsedArgs: yargs.Arguments) { ? parsedArgs.pluginName.split('/')[1] : parsedArgs.pluginName, }; - await createWorkspace('@nrwl/nx-plugin', populatedArguments); + + output.log({ + title: `Creating an Nx v${nxVersion} plugin.`, + bodyLines: [ + 'To make sure the command works reliably in all environments, and that the preset is applied correctly,', + `Nx will run "${parsedArgs.packageManager} install" several times. Please wait.`, + ], + }); + + const workspaceInfo = await createWorkspace( + '@nrwl/nx-plugin', + populatedArguments + ); + + showNxWarning(parsedArgs.pluginName); + + await recordStat({ + nxVersion, + command: 'create-nx-workspace', + useCloud: parsedArgs.nxCloud, + meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'), + }); + + if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) { + printNxCloudSuccessMessage(workspaceInfo.nxCloudInfo); + } } /** diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.ts b/packages/create-nx-workspace/bin/create-nx-workspace.ts index 9d735a836e6e6..f80e5ef82dbc5 100644 --- a/packages/create-nx-workspace/bin/create-nx-workspace.ts +++ b/packages/create-nx-workspace/bin/create-nx-workspace.ts @@ -28,6 +28,9 @@ import { withOptions, withPackageManager, } from '../src/internal-utils/yargs-options'; +import { showNxWarning } from '../src/utils/nx/show-nx-warning'; +import { printNxCloudSuccessMessage } from '../src/utils/nx/nx-cloud'; +import { messages, recordStat } from '../src/utils/nx/ab-testing'; interface Arguments extends CreateWorkspaceOptions { preset: string; @@ -129,7 +132,31 @@ export const commandsObject: yargs.Argv = yargs ) as yargs.Argv; async function main(parsedArgs: yargs.Arguments) { - await createWorkspace(parsedArgs.preset, parsedArgs); + output.log({ + title: `Creating your v${nxVersion} workspace.`, + bodyLines: [ + 'To make sure the command works reliably in all environments, and that the preset is applied correctly,', + `Nx will run "${parsedArgs.packageManager} install" several times. Please wait.`, + ], + }); + + const workspaceInfo = await createWorkspace( + parsedArgs.preset, + parsedArgs + ); + + showNxWarning(parsedArgs.name); + + await recordStat({ + nxVersion, + command: 'create-nx-workspace', + useCloud: parsedArgs.nxCloud, + meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'), + }); + + if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) { + printNxCloudSuccessMessage(workspaceInfo.nxCloudInfo); + } if (isKnownPreset(parsedArgs.preset)) { pointToTutorialAndCourse(parsedArgs.preset as Preset); diff --git a/packages/create-nx-workspace/src/create-empty-workspace.ts b/packages/create-nx-workspace/src/create-empty-workspace.ts index ab673a60f036f..ff647d5a30850 100644 --- a/packages/create-nx-workspace/src/create-empty-workspace.ts +++ b/packages/create-nx-workspace/src/create-empty-workspace.ts @@ -64,13 +64,13 @@ export async function createEmptyWorkspace( await execAndWait(fullCommand, tmpDir); workspaceSetupSpinner.succeed( - `Nx has successfully created the workspace: ${getFileName(name)}.` + `Successfully created the workspace: ${getFileName(name)}.` ); } catch (e) { workspaceSetupSpinner.fail(); if (e instanceof Error) { output.error({ - title: `Nx failed to create a workspace.`, + title: `Failed to create a workspace.`, bodyLines: mapErrorToBodyLines(e), }); } else { diff --git a/packages/create-nx-workspace/src/create-preset.ts b/packages/create-nx-workspace/src/create-preset.ts index b6fc87ffd1694..fa108393f7193 100644 --- a/packages/create-nx-workspace/src/create-preset.ts +++ b/packages/create-nx-workspace/src/create-preset.ts @@ -52,10 +52,6 @@ export async function createPreset( ...command.split(' ') ); await spawnAndWait(exec, args, directory); - - output.log({ - title: `Successfully applied preset: ${preset}.`, - }); } catch (e) { output.error({ title: `Failed to apply preset: ${preset}`, diff --git a/packages/create-nx-workspace/src/create-sandbox.ts b/packages/create-nx-workspace/src/create-sandbox.ts index fd27bad941d54..fe531b77d57cb 100644 --- a/packages/create-nx-workspace/src/create-sandbox.ts +++ b/packages/create-nx-workspace/src/create-sandbox.ts @@ -46,7 +46,7 @@ export async function createSandbox(packageManager: PackageManager) { installSpinner.fail(); if (e instanceof Error) { output.error({ - title: `Nx failed to install dependencies`, + title: `Failed to install dependencies`, bodyLines: mapErrorToBodyLines(e), }); } else { diff --git a/packages/create-nx-workspace/src/create-workspace-options.d.ts b/packages/create-nx-workspace/src/create-workspace-options.d.ts index c0ecfe190c974..1b14c13ac0830 100644 --- a/packages/create-nx-workspace/src/create-workspace-options.d.ts +++ b/packages/create-nx-workspace/src/create-workspace-options.d.ts @@ -29,4 +29,5 @@ export interface CreateWorkspaceOptions { email: string; // Email to use for the initial commit message: string; // Message to use for the initial commit }; + cliName?: string; // Name of the CLI, used when displaying outputs. e.g. nx, Nx } diff --git a/packages/create-nx-workspace/src/create-workspace.ts b/packages/create-nx-workspace/src/create-workspace.ts index ed7d090f24f07..0489c43f715b7 100644 --- a/packages/create-nx-workspace/src/create-workspace.ts +++ b/packages/create-nx-workspace/src/create-workspace.ts @@ -1,10 +1,9 @@ import { CreateWorkspaceOptions } from './create-workspace-options'; import { output } from './utils/output'; -import { printNxCloudSuccessMessage, setupNxCloud } from './utils/nx/nx-cloud'; +import { setupNxCloud } from './utils/nx/nx-cloud'; import { createSandbox } from './create-sandbox'; import { createEmptyWorkspace } from './create-empty-workspace'; import { createPreset } from './create-preset'; -import { showNxWarning } from './utils/nx/show-nx-warning'; import { setupCI } from './utils/ci/setup-ci'; import { messages, recordStat } from './utils/nx/ab-testing'; import { initializeGitRepo } from './utils/git/git'; @@ -24,15 +23,12 @@ export async function createWorkspace( skipGit = false, defaultBase = 'main', commit, + cliName, } = options; - output.log({ - title: `Nx is creating your v${nxVersion} workspace.`, - bodyLines: [ - 'To make sure the command works reliably in all environments, and that the preset is applied correctly,', - `Nx will run "${options.packageManager} install" several times. Please wait.`, - ], - }); + if (cliName) { + output.setCliName(cliName ?? 'NX'); + } const tmpDir = await createSandbox(packageManager); @@ -79,16 +75,8 @@ export async function createWorkspace( } } - showNxWarning(name); - - if (nxCloud && nxCloudInstallRes?.code === 0) { - printNxCloudSuccessMessage(nxCloudInstallRes.stdout); - } - - await recordStat({ - nxVersion, - command: 'create-nx-workspace', - useCloud: nxCloud, - meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'), - }); + return { + nxCloudInfo: nxCloudInstallRes?.stdout, + directory, + }; } diff --git a/packages/create-nx-workspace/src/utils/ci/setup-ci.ts b/packages/create-nx-workspace/src/utils/ci/setup-ci.ts index 485cdef08e897..dedff15a26b60 100644 --- a/packages/create-nx-workspace/src/utils/ci/setup-ci.ts +++ b/packages/create-nx-workspace/src/utils/ci/setup-ci.ts @@ -35,7 +35,7 @@ export async function setupCI( ciSpinner.fail(); if (e instanceof Error) { output.error({ - title: `Nx failed to generate CI workflow`, + title: `Failed to generate CI workflow`, bodyLines: mapErrorToBodyLines(e), }); } else { diff --git a/packages/create-nx-workspace/src/utils/git/git.ts b/packages/create-nx-workspace/src/utils/git/git.ts index 0668ffef41bed..9855b68e62dad 100644 --- a/packages/create-nx-workspace/src/utils/git/git.ts +++ b/packages/create-nx-workspace/src/utils/git/git.ts @@ -83,7 +83,4 @@ export async function initializeGitRepo( const message = options.commit.message || 'initial commit'; await execute(['commit', `-m "${message}"`]); } - output.log({ - title: 'Successfully initialized git.', - }); } diff --git a/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts b/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts index a6e064392ab32..66dca6128315a 100644 --- a/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts +++ b/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts @@ -24,7 +24,7 @@ export async function setupNxCloud( if (e instanceof Error) { output.error({ - title: `Nx failed to setup NxCloud`, + title: `Failed to setup NxCloud`, bodyLines: mapErrorToBodyLines(e), }); } else { diff --git a/packages/create-nx-workspace/src/utils/output.ts b/packages/create-nx-workspace/src/utils/output.ts index 429bc8586aba9..b74be435f1c90 100644 --- a/packages/create-nx-workspace/src/utils/output.ts +++ b/packages/create-nx-workspace/src/utils/output.ts @@ -10,13 +10,11 @@ import { isCI } from './ci/is-ci'; export interface CLIErrorMessageConfig { title: string; bodyLines?: string[]; - slug?: string; } export interface CLIWarnMessageConfig { title: string; bodyLines?: string[]; - slug?: string; } export interface CLINoteMessageConfig { @@ -82,7 +80,7 @@ class CLIOutput { color: string; title: string; }): void { - this.writeToStdOut(` ${this.applyNxPrefix(color, title)}${EOL}`); + this.writeToStdOut(` ${this.applyCLIPrefix(color, title)}${EOL}`); } private writeOptionalOutputBody(bodyLines?: string[]): void { @@ -93,18 +91,24 @@ class CLIOutput { bodyLines.forEach((bodyLine) => this.writeToStdOut(` ${bodyLine}${EOL}`)); } - applyNxPrefix(color = 'cyan', text: string): string { - let nxPrefix = ''; + private cliName = 'NX'; + + setCliName(name: string) { + this.cliName = name; + } + + applyCLIPrefix(color = 'cyan', text: string): string { + let cliPrefix = ''; if ((chalk as any)[color]) { - nxPrefix = `${(chalk as any)[color]('>')} ${( + cliPrefix = `${(chalk as any)[color]('>')} ${( chalk as any - ).reset.inverse.bold[color](' NX ')}`; + ).reset.inverse.bold[color](` ${this.cliName} `)}`; } else { - nxPrefix = `${chalk.keyword(color)( + cliPrefix = `${chalk.keyword(color)( '>' - )} ${chalk.reset.inverse.bold.keyword(color)(' NX ')}`; + )} ${chalk.reset.inverse.bold.keyword(color)(` ${this.cliName} `)}`; } - return `${nxPrefix} ${text}`; + return `${cliPrefix} ${text}`; } addNewline() { @@ -125,7 +129,7 @@ class CLIOutput { ); } - error({ title, slug, bodyLines }: CLIErrorMessageConfig) { + error({ title, bodyLines }: CLIErrorMessageConfig) { this.addNewline(); this.writeOutputTitle({ @@ -135,22 +139,10 @@ class CLIOutput { this.writeOptionalOutputBody(bodyLines); - /** - * Optional slug to be used in an Nx error message redirect URL - */ - if (slug && typeof slug === 'string') { - this.addNewline(); - this.writeToStdOut( - `${chalk.grey( - ' Learn more about this error: ' - )}https://errors.nx.dev/${slug}${EOL}` - ); - } - this.addNewline(); } - warn({ title, slug, bodyLines }: CLIWarnMessageConfig) { + warn({ title, bodyLines }: CLIWarnMessageConfig) { this.addNewline(); this.writeOutputTitle({ @@ -160,18 +152,6 @@ class CLIOutput { this.writeOptionalOutputBody(bodyLines); - /** - * Optional slug to be used in an Nx warning message redirect URL - */ - if (slug && typeof slug === 'string') { - this.addNewline(); - this.writeToStdOut( - `${chalk.grey( - ' Learn more about this warning: ' - )}https://errors.nx.dev/${slug}\n` - ); - } - this.addNewline(); } @@ -212,8 +192,6 @@ class CLIOutput { this.addNewline(); } - logCommand(message: string) {} - log({ title, bodyLines, color }: CLIWarnMessageConfig & { color?: string }) { this.addNewline(); diff --git a/packages/nx/src/command-line/generate.ts b/packages/nx/src/command-line/generate.ts index df88fd589da6e..ea9088b5d679f 100644 --- a/packages/nx/src/command-line/generate.ts +++ b/packages/nx/src/command-line/generate.ts @@ -333,9 +333,11 @@ export async function generate(cwd: string, args: { [k: string]: any }) { ].join('/n') ); } - logger.info( - `NX Generating ${opts.collectionName}:${normalizedGeneratorName}` - ); + if (!opts.quiet) { + logger.info( + `NX Generating ${opts.collectionName}:${normalizedGeneratorName}` + ); + } if (opts.help) { printGenHelp(opts, schema, normalizedGeneratorName, aliases);