diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.ts b/packages/create-nx-workspace/bin/create-nx-workspace.ts index 4d17dd28e88576..95cff94b92bd47 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 { DefaultLogHandler } from '../src/utils/log-handler'; +import { showNxWarning } from '../src/utils/nx/show-nx-warning'; +import { printNxCloudSuccessMessage } from '../src/utils/nx/nx-cloud'; interface Arguments extends CreateWorkspaceOptions { preset: string; @@ -129,7 +132,25 @@ export const commandsObject: yargs.Argv = yargs ) as yargs.Argv; async function main(parsedArgs: yargs.Arguments) { - await createWorkspace(parsedArgs.preset, parsedArgs); + 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 "${parsedArgs.packageManager} install" several times. Please wait.`, + ], + }); + + const workspaceInfo = await createWorkspace( + parsedArgs.preset, + parsedArgs, + new DefaultLogHandler() + ); + + showNxWarning(parsedArgs.name); + + 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 ab673a60f036fa..5be9840c836eb2 100644 --- a/packages/create-nx-workspace/src/create-empty-workspace.ts +++ b/packages/create-nx-workspace/src/create-empty-workspace.ts @@ -1,9 +1,7 @@ -import * as ora from 'ora'; import { join } from 'path'; import { CreateWorkspaceOptions } from './create-workspace-options'; import { execAndWait } from './utils/child-process-utils'; -import { mapErrorToBodyLines } from './utils/error-utils'; -import { output } from './utils/output'; +import { ProgressLogHandler } from './utils/log-handler'; import { getPackageManagerCommand, getPackageManagerVersion, @@ -24,7 +22,8 @@ export async function createEmptyWorkspace( tmpDir: string, name: string, packageManager: PackageManager, - options: T + options: T, + progressLogHandler?: ProgressLogHandler ): Promise { // Ensure to use packageManager for args // if it's not already passed in from previous process @@ -55,30 +54,36 @@ export async function createEmptyWorkspace( nxWorkspaceRoot = `\\"${nxWorkspaceRoot.slice(1, -1)}\\"`; } } - let workspaceSetupSpinner = ora( - `Creating your workspace in ${getFileName(name)}` - ).start(); + progressLogHandler?.eventStartHandler({ + displayMessage: `Creating your workspace in ${getFileName(name)}`, + id: 'workspace-setup', + status: 'start', + }); try { const fullCommand = `${pmc.exec} nx ${command} --nxWorkspaceRoot=${nxWorkspaceRoot}`; await execAndWait(fullCommand, tmpDir); - workspaceSetupSpinner.succeed( - `Nx has successfully created the workspace: ${getFileName(name)}.` - ); + progressLogHandler?.eventEndHandler({ + displayMessage: `Nx has successfully created the workspace: ${getFileName( + name + )}`, + id: 'workspace-setup', + status: 'success', + }); } catch (e) { - workspaceSetupSpinner.fail(); - if (e instanceof Error) { - output.error({ - title: `Nx failed to create a workspace.`, - bodyLines: mapErrorToBodyLines(e), + if (progressLogHandler) { + progressLogHandler.eventEndHandler({ + displayMessage: `Nx failed to create the workspace: ${getFileName( + name + )}`, + id: 'workspace-setup', + status: 'fail', }); + progressLogHandler.errorHandler(e); } else { - console.error(e); + throw e; } - process.exit(1); - } finally { - workspaceSetupSpinner.stop(); } return join(workingDir, getFileName(name)); } diff --git a/packages/create-nx-workspace/src/create-preset.ts b/packages/create-nx-workspace/src/create-preset.ts index b6fc87ffd16942..27cbc7d1548a5f 100644 --- a/packages/create-nx-workspace/src/create-preset.ts +++ b/packages/create-nx-workspace/src/create-preset.ts @@ -1,5 +1,4 @@ import { CreateWorkspaceOptions } from './create-workspace-options'; -import { output } from './utils/output'; import { getPackageManagerCommand, getPackageManagerVersion, @@ -7,12 +6,14 @@ import { } from './utils/package-manager'; import { spawnAndWait } from './utils/child-process-utils'; import { unparse } from './utils/unparse'; +import { ProgressLogHandler } from './utils/log-handler'; export async function createPreset( preset: string, parsedArgs: T, packageManager: PackageManager, - directory: string + directory: string, + progressLogHandler?: ProgressLogHandler ): Promise { const { skipGit, ci, commit, nxCloud, ...restArgs } = parsedArgs; @@ -44,6 +45,13 @@ export async function createPreset( } const command = `g ${preset}:preset ${args}`; + progressLogHandler?.eventStartHandler({ + displayMessage: `Applying your preset: ${preset}`, + id: 'apply-preset', + status: 'start', + interactive: true, + }); + try { const [exec, ...args] = pmc.exec.split(' '); args.push( @@ -53,14 +61,21 @@ export async function createPreset( ); await spawnAndWait(exec, args, directory); - output.log({ - title: `Successfully applied preset: ${preset}.`, + progressLogHandler?.eventEndHandler({ + displayMessage: `Successfully applied preset: ${preset}.`, + id: 'apply-preset', + status: 'success', }); } catch (e) { - output.error({ - title: `Failed to apply preset: ${preset}`, - bodyLines: ['See above'], - }); - process.exit(1); + if (progressLogHandler) { + progressLogHandler?.eventEndHandler({ + displayMessage: `Failed to apply preset: ${preset}`, + id: 'apply-preset', + status: 'fail', + }); + progressLogHandler?.errorHandler(e); + } else { + throw e; + } } } diff --git a/packages/create-nx-workspace/src/create-sandbox.ts b/packages/create-nx-workspace/src/create-sandbox.ts index fd27bad941d54a..4c8b6c9b74c97a 100644 --- a/packages/create-nx-workspace/src/create-sandbox.ts +++ b/packages/create-nx-workspace/src/create-sandbox.ts @@ -1,6 +1,5 @@ import { writeFileSync } from 'fs'; import { dirSync } from 'tmp'; -import * as ora from 'ora'; import { join } from 'path'; import { @@ -9,19 +8,24 @@ import { PackageManager, } from './utils/package-manager'; import { execAndWait } from './utils/child-process-utils'; -import { output } from './utils/output'; import { nxVersion } from './utils/nx/nx-version'; import { mapErrorToBodyLines } from './utils/error-utils'; +import { ProgressLogHandler } from './utils/log-handler'; /** * Creates a temporary directory and installs Nx in it. * @param packageManager package manager to use * @returns directory where Nx is installed */ -export async function createSandbox(packageManager: PackageManager) { - const installSpinner = ora( - `Installing dependencies with ${packageManager}` - ).start(); +export async function createSandbox( + packageManager: PackageManager, + progressLogHandler?: ProgressLogHandler +) { + progressLogHandler?.eventStartHandler({ + displayMessage: `Installing dependencies with ${packageManager}`, + id: 'install-dependencies', + status: 'start', + }); const { install } = getPackageManagerCommand(packageManager); @@ -41,20 +45,22 @@ export async function createSandbox(packageManager: PackageManager) { await execAndWait(install, tmpDir); - installSpinner.succeed(); + progressLogHandler?.eventEndHandler({ + displayMessage: `Dependencies installed with ${packageManager}`, + id: 'install-dependencies', + status: 'success', + }); } catch (e) { - installSpinner.fail(); - if (e instanceof Error) { - output.error({ - title: `Nx failed to install dependencies`, - bodyLines: mapErrorToBodyLines(e), + if (progressLogHandler) { + progressLogHandler.eventEndHandler({ + displayMessage: `Failed to install dependencies with ${packageManager}`, + id: 'install-dependencies', + status: 'fail', }); + progressLogHandler.errorHandler(e); } else { - console.error(e); + throw e; } - process.exit(1); - } finally { - installSpinner.stop(); } return tmpDir; diff --git a/packages/create-nx-workspace/src/create-workspace.ts b/packages/create-nx-workspace/src/create-workspace.ts index ed7d090f24f075..45e5e0217acd3f 100644 --- a/packages/create-nx-workspace/src/create-workspace.ts +++ b/packages/create-nx-workspace/src/create-workspace.ts @@ -1,5 +1,4 @@ import { CreateWorkspaceOptions } from './create-workspace-options'; -import { output } from './utils/output'; import { printNxCloudSuccessMessage, setupNxCloud } from './utils/nx/nx-cloud'; import { createSandbox } from './create-sandbox'; import { createEmptyWorkspace } from './create-empty-workspace'; @@ -11,11 +10,13 @@ import { initializeGitRepo } from './utils/git/git'; import { nxVersion } from './utils/nx/nx-version'; import { getThirdPartyPreset } from './utils/preset/get-third-party-preset'; import { mapErrorToBodyLines } from './utils/error-utils'; +import { ProgressLogHandler } from './utils/log-handler'; export async function createWorkspace( preset: string, - options: T -) { + options: T, + logHandler?: ProgressLogHandler +): Promise<{ nxCloudInfo?: string }> { const { packageManager, name, @@ -26,22 +27,15 @@ export async function createWorkspace( commit, } = 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.`, - ], - }); - - const tmpDir = await createSandbox(packageManager); + const tmpDir = await createSandbox(packageManager, logHandler); // nx new requires preset currently. We should probably make it optional. const directory = await createEmptyWorkspace( tmpDir, name, packageManager, - { ...options, preset } + { ...options, preset }, + logHandler ); // If the preset is a third-party preset, we need to call createPreset to install it @@ -49,7 +43,13 @@ export async function createWorkspace( // In createEmptyWorkspace, it will call `nx new` -> `@nrwl/workspace newGenerator` -> `@nrwl/workspace generatePreset`. const thirdPartyPreset = await getThirdPartyPreset(preset); if (thirdPartyPreset) { - await createPreset(thirdPartyPreset, options, packageManager, directory); + await createPreset( + thirdPartyPreset, + options, + packageManager, + directory, + logHandler + ); } let nxCloudInstallRes; @@ -61,28 +61,12 @@ export async function createWorkspace( name, ci, packageManager, - nxCloud && nxCloudInstallRes?.code === 0 + nxCloud && nxCloudInstallRes?.code === 0, + logHandler ); } if (!skipGit) { - try { - await initializeGitRepo(directory, { defaultBase, commit }); - } catch (e) { - if (e instanceof Error) { - output.error({ - title: 'Could not initialize git repository', - bodyLines: mapErrorToBodyLines(e), - }); - } else { - console.error(e); - } - } - } - - showNxWarning(name); - - if (nxCloud && nxCloudInstallRes?.code === 0) { - printNxCloudSuccessMessage(nxCloudInstallRes.stdout); + initializeGitRepo(directory, { defaultBase, commit }, logHandler); } await recordStat({ @@ -91,4 +75,8 @@ export async function createWorkspace( useCloud: nxCloud, meta: messages.codeOfSelectedPromptMessage('nxCloudCreation'), }); + + return { + nxCloudInfo: nxCloudInstallRes?.stdout, + }; } diff --git a/packages/create-nx-workspace/src/utils/child-process-utils.ts b/packages/create-nx-workspace/src/utils/child-process-utils.ts index 9b57d4cb971225..a141a23abb3110 100644 --- a/packages/create-nx-workspace/src/utils/child-process-utils.ts +++ b/packages/create-nx-workspace/src/utils/child-process-utils.ts @@ -34,7 +34,9 @@ export function execAndWait(command: string, cwd: string) { const logFile = join(cwd, 'error.log'); writeFileSync(logFile, `${stdout}\n${stderr}`); const message = stderr && stderr.trim().length ? stderr : stdout; - rej(new CreateNxWorkspaceError(message, error.code, logFile)); + rej( + new CreateNxWorkspaceError(message, { code: error.code, logFile }) + ); } else { res({ code: 0, stdout }); } 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 485cdef08e8970..0b4eb9ac61a7e7 100644 --- a/packages/create-nx-workspace/src/utils/ci/setup-ci.ts +++ b/packages/create-nx-workspace/src/utils/ci/setup-ci.ts @@ -1,9 +1,7 @@ -import * as ora from 'ora'; import { join } from 'path'; import { execAndWait } from '../child-process-utils'; -import { mapErrorToBodyLines } from '../error-utils'; -import { output } from '../output'; +import { ProgressLogHandler } from '../log-handler'; import { getPackageManagerCommand, PackageManager } from '../package-manager'; import { getFileName } from '../string-utils'; @@ -11,39 +9,43 @@ export async function setupCI( name: string, ci: string, packageManager: PackageManager, - nxCloudSuccessfullyInstalled: boolean + nxCloudSuccessfullyInstalled: boolean, + logHandler?: ProgressLogHandler ) { + logHandler?.eventStartHandler({ + displayMessage: `Generating CI workflow`, + id: 'generate-ci-workflow', + status: 'start', + }); if (!nxCloudSuccessfullyInstalled) { - output.error({ - title: `CI workflow generation skipped`, - bodyLines: [ - `Nx Cloud was not installed`, - `The autogenerated CI workflow requires Nx Cloud to be set-up.`, - ], + logHandler?.eventEndHandler({ + displayMessage: `CI workflow generation skipped (Nx Cloud not installed)`, + id: 'generate-ci-workflow', + status: 'fail', }); } - const ciSpinner = ora(`Generating CI workflow`).start(); try { const pmc = getPackageManagerCommand(packageManager); const res = await execAndWait( `${pmc.exec} nx g @nrwl/workspace:ci-workflow --ci=${ci}`, join(process.cwd(), getFileName(name)) ); - ciSpinner.succeed('CI workflow has been generated successfully'); + logHandler?.eventEndHandler({ + displayMessage: `CI workflow generated`, + id: 'generate-ci-workflow', + status: 'success', + }); return res; } catch (e) { - ciSpinner.fail(); - if (e instanceof Error) { - output.error({ - title: `Nx failed to generate CI workflow`, - bodyLines: mapErrorToBodyLines(e), + if (logHandler) { + logHandler.eventEndHandler({ + displayMessage: `Failed to generate CI workflow`, + id: 'generate-ci-workflow', + status: 'fail', }); + logHandler.errorHandler(e); } else { - console.error(e); + throw e; } - - process.exit(1); - } finally { - ciSpinner.stop(); } } diff --git a/packages/create-nx-workspace/src/utils/error-utils.ts b/packages/create-nx-workspace/src/utils/error-utils.ts index d36f589a158861..9dc1e724360b2d 100644 --- a/packages/create-nx-workspace/src/utils/error-utils.ts +++ b/packages/create-nx-workspace/src/utils/error-utils.ts @@ -1,10 +1,23 @@ export class CreateNxWorkspaceError extends Error { + public code?: number | null; + public logFile?: string; + public title?: string; + public bodyLines?: string[]; + constructor( - public logMessage: string, - public code: number | null | undefined, - public logFile: string + message: string, + opts?: { + title?: string; + code?: number | null; + logFile?: string; + bodyLines?: string[]; + } ) { - super(logMessage); + super(message); + this.code = opts?.code; + this.logFile = opts?.logFile; + this.title = opts?.title; + this.bodyLines = opts?.bodyLines; this.name = 'CreateNxWorkspaceError'; } } diff --git a/packages/create-nx-workspace/src/utils/git/git.ts b/packages/create-nx-workspace/src/utils/git/git.ts index 0668ffef41bedd..cf348560c0de3d 100644 --- a/packages/create-nx-workspace/src/utils/git/git.ts +++ b/packages/create-nx-workspace/src/utils/git/git.ts @@ -1,6 +1,6 @@ import { execSync, spawn, SpawnOptions } from 'child_process'; import { deduceDefaultBase } from './default-base'; -import { output } from '../output'; +import { ProgressLogHandler } from '../log-handler'; export function checkGitVersion(): string | null | undefined { try { @@ -16,74 +16,100 @@ export async function initializeGitRepo( options: { defaultBase: string; commit?: { message: string; name: string; email: string }; - } + }, + logHandler?: ProgressLogHandler ) { - const execute = (args: ReadonlyArray, ignoreErrorStream = false) => { - const outputStream = 'ignore'; - const errorStream = ignoreErrorStream ? 'ignore' : process.stderr; - const spawnOptions: SpawnOptions = { - stdio: [process.stdin, outputStream, errorStream], - shell: true, - cwd: directory, - env: { - ...process.env, - ...(options.commit?.name - ? { - GIT_AUTHOR_NAME: options.commit.name, - GIT_COMMITTER_NAME: options.commit.name, - } - : {}), - ...(options.commit?.email - ? { - GIT_AUTHOR_EMAIL: options.commit.email, - GIT_COMMITTER_EMAIL: options.commit.email, - } - : {}), - }, + logHandler?.eventStartHandler({ + displayMessage: 'Initializing git repository', + id: 'initialize-git', + status: 'start', + }); + try { + const execute = ( + args: ReadonlyArray, + ignoreErrorStream = false + ) => { + const outputStream = 'ignore'; + const errorStream = ignoreErrorStream ? 'ignore' : process.stderr; + const spawnOptions: SpawnOptions = { + stdio: [process.stdin, outputStream, errorStream], + shell: true, + cwd: directory, + env: { + ...process.env, + ...(options.commit?.name + ? { + GIT_AUTHOR_NAME: options.commit.name, + GIT_COMMITTER_NAME: options.commit.name, + } + : {}), + ...(options.commit?.email + ? { + GIT_AUTHOR_EMAIL: options.commit.email, + GIT_COMMITTER_EMAIL: options.commit.email, + } + : {}), + }, + }; + return new Promise((resolve, reject) => { + spawn('git', args, spawnOptions).on('close', (code) => { + if (code === 0) { + resolve(); + } else { + reject(code); + } + }); + }); }; - return new Promise((resolve, reject) => { - spawn('git', args, spawnOptions).on('close', (code) => { - if (code === 0) { - resolve(); - } else { - reject(code); - } + const gitVersion = checkGitVersion(); + if (!gitVersion) { + return; + } + const insideRepo = await execute( + ['rev-parse', '--is-inside-work-tree'], + true + ).then( + () => true, + () => false + ); + if (insideRepo) { + logHandler?.eventEndHandler({ + id: 'initialize-git', + displayMessage: + 'Directory is already under version control. Skipping initialization of git.', + status: 'success', }); - }); - }; - const gitVersion = checkGitVersion(); - if (!gitVersion) { - return; - } - const insideRepo = await execute( - ['rev-parse', '--is-inside-work-tree'], - true - ).then( - () => true, - () => false - ); - if (insideRepo) { - output.log({ - title: - 'Directory is already under version control. Skipping initialization of git.', - }); - return; - } - const defaultBase = options.defaultBase || deduceDefaultBase(); - const [gitMajor, gitMinor] = gitVersion.split('.'); + return; + } + const defaultBase = options.defaultBase || deduceDefaultBase(); + const [gitMajor, gitMinor] = gitVersion.split('.'); - if (+gitMajor > 2 || (+gitMajor === 2 && +gitMinor >= 28)) { - await execute(['init', '-b', defaultBase]); - } else { - await execute(['init']); - await execute(['checkout', '-b', defaultBase]); // Git < 2.28 doesn't support -b on git init. - } - await execute(['add', '.']); - if (options.commit) { - const message = options.commit.message || 'initial commit'; - await execute(['commit', `-m "${message}"`]); + if (+gitMajor > 2 || (+gitMajor === 2 && +gitMinor >= 28)) { + await execute(['init', '-b', defaultBase]); + } else { + await execute(['init']); + await execute(['checkout', '-b', defaultBase]); // Git < 2.28 doesn't support -b on git init. + } + await execute(['add', '.']); + if (options.commit) { + const message = options.commit.message || 'initial commit'; + await execute(['commit', `-m "${message}"`]); + } + logHandler?.eventEndHandler({ + displayMessage: 'Initialized git repository', + id: 'initialize-git', + status: 'success', + }); + } catch (e) { + if (logHandler) { + logHandler.eventEndHandler({ + displayMessage: 'Failed to initialize git repository', + id: 'initialize-git', + status: 'fail', + }); + logHandler.errorHandler(e); + } else { + throw e; + } } - output.log({ - title: 'Successfully initialized git.', - }); } diff --git a/packages/create-nx-workspace/src/utils/log-handler.ts b/packages/create-nx-workspace/src/utils/log-handler.ts new file mode 100644 index 00000000000000..c9a79108a7ee5d --- /dev/null +++ b/packages/create-nx-workspace/src/utils/log-handler.ts @@ -0,0 +1,87 @@ +import ora = require('ora'); +import { CreateNxWorkspaceError, mapErrorToBodyLines } from './error-utils'; +import { output } from './output'; + +interface BaseCreateNxWorkspaceEvent { + id: CreateNxWorkspaceEventId; + displayMessage: string; + interactive?: boolean; +} + +export type SectionStartEvent = BaseCreateNxWorkspaceEvent & { + status: 'start'; +}; +export type SectionEndEvent = BaseCreateNxWorkspaceEvent & { + status: 'success' | 'fail'; +}; + +export interface ProgressLogHandler { + errorHandler: (error: Error | unknown) => void | never; + eventStartHandler: (event: SectionStartEvent) => void; + eventEndHandler: (event: SectionEndEvent) => void; +} + +export type CreateNxWorkspaceEventId = + | 'create-sandbox' + | 'initialize-git' + | 'workspace-setup' + | 'install-dependencies' + | 'apply-preset' + | 'generate-ci-workflow' + | 'setup-nx-cloud'; + +export class DefaultLogHandler implements ProgressLogHandler { + private spinner?: ora.Ora; + + eventStartHandler(event: SectionStartEvent) { + if (this.spinner) { + this.spinner.succeed(); + this.spinner.stop(); + this.spinner = undefined; + } + if (!event.interactive) { + this.spinner = ora(event.displayMessage); + } else { + output.log({ title: event.displayMessage }); + } + } + + eventEndHandler(event: SectionEndEvent) { + if (this.spinner) { + if (event.status === 'fail') { + this.spinner.fail(event.displayMessage); + } else { + this.spinner.succeed(event.displayMessage); + } + this.spinner.stop(); + } else { + if (event.status === 'fail') { + output.error({ title: event.displayMessage }); + } else { + output.log({ title: event.displayMessage }); + } + } + this.spinner = undefined; + } + + errorHandler(e: Error | unknown) { + this.spinner?.fail(); + const isNxError = e instanceof CreateNxWorkspaceError; + const title = + isNxError && e.title + ? e.title + : 'An error occurred while creating the workspace.'; + if (e instanceof Error) { + const bodyLines = + isNxError && e.bodyLines ? e.bodyLines : mapErrorToBodyLines(e); + output.error({ title, bodyLines }); + } else { + console.error(e); + } + process.exit(1); + } + + log(...args: unknown[]) { + console.log(...args); + } +} 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 afc1de5a915965..61b31eb9d96325 100644 --- a/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts +++ b/packages/create-nx-workspace/src/utils/nx/nx-cloud.ts @@ -1,39 +1,44 @@ -import * as ora from 'ora'; import { join } from 'path'; import { execAndWait } from '../child-process-utils'; import { output } from '../output'; import { getPackageManagerCommand, PackageManager } from '../package-manager'; import { getFileName } from '../string-utils'; import { mapErrorToBodyLines } from '../error-utils'; +import { ProgressLogHandler } from '../log-handler'; export async function setupNxCloud( name: string, - packageManager: PackageManager + packageManager: PackageManager, + progressLogHandler?: ProgressLogHandler ) { - const nxCloudSpinner = ora(`Setting up NxCloud`).start(); + progressLogHandler?.eventStartHandler({ + displayMessage: `Setting up NxCloud`, + id: 'setup-nx-cloud', + status: 'start', + }); try { const pmc = getPackageManagerCommand(packageManager); const res = await execAndWait( `${pmc.exec} nx g @nrwl/nx-cloud:init --no-analytics --installationSource=create-nx-workspace`, join(process.cwd(), getFileName(name)) ); - nxCloudSpinner.succeed('NxCloud has been set up successfully'); + progressLogHandler?.eventEndHandler({ + displayMessage: `NxCloud has been set up successfully`, + id: 'setup-nx-cloud', + status: 'success', + }); return res; } catch (e) { - nxCloudSpinner.fail(); - - if (e instanceof Error) { - output.error({ - title: `Nx failed to setup NxCloud`, - bodyLines: mapErrorToBodyLines(e), + if (progressLogHandler) { + progressLogHandler.eventEndHandler({ + displayMessage: `Failed to set up NxCloud`, + id: 'setup-nx-cloud', + status: 'fail', }); + progressLogHandler.errorHandler(e); } else { - console.error(e); + throw e; } - - process.exit(1); - } finally { - nxCloudSpinner.stop(); } }