diff --git a/packages/nx/src/command-line/release/changelog.ts b/packages/nx/src/command-line/release/changelog.ts index b9161ec8c0cba..6f37baf5f774a 100644 --- a/packages/nx/src/command-line/release/changelog.ts +++ b/packages/nx/src/command-line/release/changelog.ts @@ -12,7 +12,6 @@ import { FsTree, Tree } from '../../generators/tree'; import { registerTsProject } from '../../plugins/js/utils/register'; import { createProjectGraphAsync } from '../../project-graph/project-graph'; import { interpolate } from '../../tasks-runner/utils'; -import { logger } from '../../utils/logger'; import { output } from '../../utils/output'; import { handleErrors } from '../../utils/params'; import { joinPathFragments } from '../../utils/path'; @@ -476,12 +475,6 @@ async function applyChangesAndExit( await postGitTask(latestCommit); } - if (args.dryRun) { - logger.warn( - `\nNOTE: The "dryRun" flag means no changelogs were actually created.` - ); - } - return 0; } diff --git a/packages/nx/src/command-line/release/command-object.ts b/packages/nx/src/command-line/release/command-object.ts index 856137d4cc539..4ccc195841d5f 100644 --- a/packages/nx/src/command-line/release/command-object.ts +++ b/packages/nx/src/command-line/release/command-object.ts @@ -1,5 +1,6 @@ import { Argv, CommandModule, showHelp } from 'yargs'; import { readNxJson } from '../../project-graph/file-utils'; +import { logger } from '../../utils/logger'; import { OutputStyle, RunManyOptions, @@ -159,15 +160,18 @@ const releaseCommand: CommandModule = { } return true; }), - handler: (args) => - import('./release') - .then((m) => m.releaseCLIHandler(args)) - .then((versionDataOrExitCode) => { - if (typeof versionDataOrExitCode === 'number') { - return process.exit(versionDataOrExitCode); - } - process.exit(0); - }), + handler: async (args) => { + const release = await import('./release'); + const result = await release.releaseCLIHandler(args); + if (args.dryRun) { + logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`); + } + + if (typeof result === 'number') { + process.exit(result); + } + process.exit(0); + }, }; const versionCommand: CommandModule = { @@ -195,15 +199,18 @@ const versionCommand: CommandModule = { 'Whether or not to stage the changes made by this command. Useful when combining this command with changelog generation.', }) ), - handler: (args) => - import('./version') - .then((m) => m.releaseVersionCLIHandler(args)) - .then((versionDataOrExitCode) => { - if (typeof versionDataOrExitCode === 'number') { - return process.exit(versionDataOrExitCode); - } - process.exit(0); - }), + handler: async (args) => { + const release = await import('./version'); + const result = await release.releaseVersionCLIHandler(args); + if (args.dryRun) { + logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`); + } + + if (typeof result === 'number') { + process.exit(result); + } + process.exit(0); + }, }; const changelogCommand: CommandModule = { @@ -254,10 +261,16 @@ const changelogCommand: CommandModule = { }) ), handler: async (args) => { - const status = await ( - await import('./changelog') - ).releaseChangelogCLIHandler(args); - process.exit(status); + const release = await import('./changelog'); + const result = await release.releaseChangelogCLIHandler(args); + if (args.dryRun) { + logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`); + } + + if (typeof result === 'number') { + process.exit(result); + } + process.exit(0); }, }; @@ -284,6 +297,10 @@ const publishCommand: CommandModule = { const status = await ( await import('./publish') ).releasePublishCLIHandler(coerceParallelOption(withOverrides(args, 2))); + if (args.dryRun) { + logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`); + } + process.exit(status); }, }; diff --git a/packages/nx/src/command-line/release/publish.ts b/packages/nx/src/command-line/release/publish.ts index c197f1b806f1d..3d88a4f54eb1d 100644 --- a/packages/nx/src/command-line/release/publish.ts +++ b/packages/nx/src/command-line/release/publish.ts @@ -10,7 +10,6 @@ import { createOverrides, readGraphFileFromGraphArg, } from '../../utils/command-line-utils'; -import { logger } from '../../utils/logger'; import { handleErrors } from '../../utils/params'; import { projectHasTarget } from '../../utils/project-graph-utils'; import { generateGraph } from '../graph/graph'; @@ -120,12 +119,6 @@ export async function releasePublish( } } - if (_args.dryRun) { - logger.warn( - `\nNOTE: The "dryRun" flag means no projects were actually published.` - ); - } - return overallExitStatus; } diff --git a/packages/nx/src/command-line/release/release.ts b/packages/nx/src/command-line/release/release.ts index 76592e62ecda9..fc980be8a23d6 100644 --- a/packages/nx/src/command-line/release/release.ts +++ b/packages/nx/src/command-line/release/release.ts @@ -150,15 +150,13 @@ export async function release( if (shouldPublish) { await releasePublish(args); } else { - console.log('Skipped publishing packages.'); + output.logSingleLine('Skipped publishing packages.'); } return versionResult; } async function promptForPublish(): Promise { - console.log('\n'); - try { const reply = await prompt<{ confirmation: boolean }>([ { @@ -169,7 +167,6 @@ async function promptForPublish(): Promise { ]); return reply.confirmation; } catch (e) { - console.log('\n'); // Handle the case where the user exits the prompt with ctrl+c return false; } diff --git a/packages/nx/src/command-line/release/utils/github.ts b/packages/nx/src/command-line/release/utils/github.ts index 3fc635788dab9..9ea2009cf62b8 100644 --- a/packages/nx/src/command-line/release/utils/github.ts +++ b/packages/nx/src/command-line/release/utils/github.ts @@ -103,45 +103,27 @@ export async function createOrUpdateGithubRelease( } } - const reply = await prompt<{ open: 'Yes' | 'No' }>([ - { - name: 'open', - message: - 'Do you want to finish creating the release manually in your browser?', - type: 'autocomplete', - choices: [ - { - name: 'Yes', - hint: 'It will pre-populate the form for you', - }, - { - name: 'No', - }, - ], - initial: 0, - }, - ]).catch(() => { - return { open: 'No' }; - }); - - if (reply.open === 'Yes') { - const open = require('open'); - await open(result.url) - .then(() => { - console.info( - `\nFollow up in the browser to manually create the release:\n\n` + - chalk.underline(chalk.cyan(result.url)) + - `\n` - ); - }) - .catch(() => { - console.info( - `Open this link to manually create a release: \n` + - chalk.underline(chalk.cyan(result.url)) + - '\n' - ); - }); + const shouldContinueInGitHub = await promptForContinueInGitHub(); + if (!shouldContinueInGitHub) { + return; } + + const open = require('open'); + await open(result.url) + .then(() => { + console.info( + `\nFollow up in the browser to manually create the release:\n\n` + + chalk.underline(chalk.cyan(result.url)) + + `\n` + ); + }) + .catch(() => { + console.info( + `Open this link to manually create a release: \n` + + chalk.underline(chalk.cyan(result.url)) + + '\n' + ); + }); } /** @@ -170,6 +152,33 @@ export async function createOrUpdateGithubRelease( } } +async function promptForContinueInGitHub(): Promise { + try { + const reply = await prompt<{ open: 'Yes' | 'No' }>([ + { + name: 'open', + message: + 'Do you want to finish creating the release manually in your browser?', + type: 'autocomplete', + choices: [ + { + name: 'Yes', + hint: 'It will pre-populate the form for you', + }, + { + name: 'No', + }, + ], + initial: 0, + }, + ]); + return reply.open === 'Yes'; + } catch (e) { + // Handle the case where the user exits the prompt with ctrl+c + process.exit(1); + } +} + async function syncGithubRelease( githubRequestConfig: GithubRequestConfig, release: GithubReleaseOptions, diff --git a/packages/nx/src/command-line/release/version.ts b/packages/nx/src/command-line/release/version.ts index bb982f6cbef8c..d0fcc53ce5a3a 100644 --- a/packages/nx/src/command-line/release/version.ts +++ b/packages/nx/src/command-line/release/version.ts @@ -10,7 +10,6 @@ import { import { NxJsonConfiguration, joinPathFragments, - logger, output, workspaceRoot, } from '../../devkit-exports'; @@ -281,10 +280,6 @@ export async function releaseVersion( } } - if (args.dryRun) { - logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`); - } - return { // An overall workspace version cannot be relevant when filtering to independent projects workspaceVersion: undefined, @@ -422,10 +417,6 @@ export async function releaseVersion( } } - if (args.dryRun) { - logger.warn(`\nNOTE: The "dryRun" flag means no changes were made.`); - } - return { workspaceVersion, projectsVersionData: versionData,