From c8cf46010c4c72516e0009f9ce3918e973c3ff17 Mon Sep 17 00:00:00 2001 From: linbudu599 Date: Fri, 8 Apr 2022 10:30:21 +0800 Subject: [PATCH] feat: support quick release mode --- packages/rtt/package.json | 2 +- scripts/release/index.ts | 117 ++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/packages/rtt/package.json b/packages/rtt/package.json index 2753b49..b9490f4 100644 --- a/packages/rtt/package.json +++ b/packages/rtt/package.json @@ -1,6 +1,6 @@ { "name": "@llab/rtt", - "version": "0.0.2-4", + "version": "0.0.4", "description": "", "main": "./dist/index.js", "license": "MIT", diff --git a/scripts/release/index.ts b/scripts/release/index.ts index dc457b5..4deb801 100644 --- a/scripts/release/index.ts +++ b/scripts/release/index.ts @@ -59,6 +59,8 @@ export default function useReleaseProject(cli: CAC) { ) => { const { dry = false, quick = false } = options ?? {}; + if (quick) releaseType = 'patch'; + const dryRunInfoLogger = (msg: MaybeArray) => dry ? consola.info( @@ -109,7 +111,6 @@ export default function useReleaseProject(cli: CAC) { } else { projectReleaseType = releaseType; } - } else if (quick) { } else { projectReleaseType = ( await enquirer.prompt<{ type: ReleaseType }>({ @@ -128,6 +129,8 @@ export default function useReleaseProject(cli: CAC) { 'package.json' ); + consola.info(`Release Type: ${chalk.cyan(projectReleaseType)}`); + const { version: rawVersion, name: packageName } = CLIUtils.readJsonSync(projectPackageJsonPath); @@ -153,7 +156,9 @@ export default function useReleaseProject(cli: CAC) { dryRunInfoLogger(`Release ${chalk.cyan(releaseTag)}?`); - const confirmVersion = await CLIUtils.createConfirmSelector('Confirm?'); + const confirmVersion = quick + ? true + : await CLIUtils.createConfirmSelector('Confirm?'); if (!confirmVersion) { consola.info('Release aborted.'); @@ -194,62 +199,66 @@ export default function useReleaseProject(cli: CAC) { )}) built successfully.` ); - const { stdout } = await execa('git', ['diff'], { - stdio: 'pipe', - cwd: projectDirPath, - }); + if (quick) { + consola.info(`Quick release mode. Skipping git flow.`); + } else { + const { stdout } = await execa('git', ['diff'], { + stdio: 'pipe', + cwd: projectDirPath, + }); - if (!stdout) { - consola.error('No commit changes found, exit.'); - process.exit(0); - } + if (!stdout) { + consola.error('No commit changes found, exit.'); + process.exit(0); + } - await CLIUtils.useChildProcess( - `git add ${projectDirPath} --verbose --dry-run` - ); + await CLIUtils.useChildProcess( + `git add ${projectDirPath} --verbose --dry-run` + ); - const gitCZCommandArgs = [ - '--type=release', - `--scope=${projectToRelease.split('-')[0]}`, - `--subject=Release ${releaseTag}`, - '--non-interactive', - ]; - - dry - ? consola.info( - `${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan( - `git-cz ${gitCZCommandArgs.join(' ')}` - )}` - ) - : await CLIUtils.useChildProcess( - `git-cz --${gitCZCommandArgs.join('')}` - ); + const gitCZCommandArgs = [ + '--type=release', + `--scope=${projectToRelease.split('-')[0]}`, + `--subject=Release ${releaseTag}`, + '--non-interactive', + ]; - dry - ? consola.info( - `${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan( - `git tag ${releaseTag}` - )}` - ) - : await CLIUtils.useChildProcess(`git tag ${releaseTag}`); - - dry - ? consola.info( - `${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan( - `git push origin refs/tags/${releaseTag} --verbose --progress` - )}` - ) - : await CLIUtils.useChildProcess( - `git ${[ - 'push', - 'origin', - `refs/tags/${releaseTag}`, - '--verbose', - '--progress', - ].join(' ')}` - ); + dry + ? consola.info( + `${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan( + `git-cz ${gitCZCommandArgs.join(' ')}` + )}` + ) + : await CLIUtils.useChildProcess( + `git-cz --${gitCZCommandArgs.join('')}` + ); + + dry + ? consola.info( + `${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan( + `git tag ${releaseTag}` + )}` + ) + : await CLIUtils.useChildProcess(`git tag ${releaseTag}`); + + dry + ? consola.info( + `${chalk.white('DRY RUN MODE')}: Executing >>> ${chalk.cyan( + `git push origin refs/tags/${releaseTag} --verbose --progress` + )}` + ) + : await CLIUtils.useChildProcess( + `git ${[ + 'push', + 'origin', + `refs/tags/${releaseTag}`, + '--verbose', + '--progress', + ].join(' ')}` + ); + } - dryRunInfoLogger(['Pubishing package...']); + dryRunInfoLogger('Pubishing package...'); const { stdout: logAs } = await execa( 'npm', @@ -280,7 +289,7 @@ export default function useReleaseProject(cli: CAC) { } ); - dryRunSuccessLogger(['Package published.']); + dryRunSuccessLogger('Package published.'); } ); }