diff --git a/README.md b/README.md index 8df1e1e..988dde7 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ npx vr publish | -s --skip-npm-publish | Skip npm publish | | -sc --skip-changelog | Skip generate changelog | | -sgt --skip-git-tag | Skip git tag | +| -nt --npm-tag \ | npm tag | #### changelog @@ -90,9 +91,10 @@ npx vr publish #### publish -| 参数 | 说明 | +| Params | Instructions | | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | -c --check-remote-version | Detects whether the remote version of the npm package is the same as the package version to be published locally, and if it is, skip the release | +| -nt --npm-tag \ | npm tag | ### Custom Handle @@ -124,14 +126,16 @@ release({ task }) interface PublishCommandOptions { preRelease?: boolean checkRemoteVersion?: boolean + npmTag?: string } -function publish({ preRelease, checkRemoteVersion }: PublishCommandOptions): Promise +function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise function updateVersion(version: string): void interface ReleaseCommandOptions { remote?: string skipNpmPublish?: boolean skipChangelog?: boolean skipGitTag?: boolean + npmTag?: string task?(): Promise } function release(options: ReleaseCommandOptions): Promise diff --git a/README.zh-CN.md b/README.zh-CN.md index 8650e70..0067d0d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -71,6 +71,7 @@ npx vr publish | -s --skip-npm-publish | 跳过 npm 发布 | | -sc --skip-changelog | 跳过生成变更日志 | | -sgt --skip-git-tag | 跳过 git tag | +| -nt --npm-tag \ | npm tag | #### changelog @@ -93,6 +94,7 @@ npx vr publish | 参数 | 说明 | | ------------------------- | --------------------------------------------------------------------- | | -c --check-remote-version | 检测npm包的远程版本是否与要在本地发布的包版本相同,如果是,则跳过发布 | +| -nt --npm-tag \ | npm tag | ### 自定义处理 @@ -124,14 +126,16 @@ release({ task }) interface PublishCommandOptions { preRelease?: boolean checkRemoteVersion?: boolean + npmTag?: string } -function publish({ preRelease, checkRemoteVersion }: PublishCommandOptions): Promise +function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise function updateVersion(version: string): void interface ReleaseCommandOptions { remote?: string skipNpmPublish?: boolean skipChangelog?: boolean skipGitTag?: boolean + npmTag?: string task?(): Promise } function release(options: ReleaseCommandOptions): Promise diff --git a/bin/index.js b/bin/index.js index ba7f75b..9e34ddf 100644 --- a/bin/index.js +++ b/bin/index.js @@ -10,12 +10,14 @@ program .option('-s --skip-npm-publish', 'Skip npm publish') .option('-sc --skip-changelog', 'Skip generate changelog') .option('-sgt --skip-git-tag', 'Skip git tag') + .option('-nt --npm-tag ', 'Npm tag') .description('Release all packages and generate changelogs') .action(async (options) => release(options)) program .command('publish') .option('-c --check-remote-version', 'Check remote version') + .option('-nt --npm-tag ', 'Npm tag') .description('Publish to npm') .action(async (options) => publish(options)) diff --git a/src/release.ts b/src/release.ts index 5740385..6b96f78 100644 --- a/src/release.ts +++ b/src/release.ts @@ -19,11 +19,13 @@ async function isWorktreeEmpty() { return !ret.stdout } -interface PublishCommandOptions { +export interface PublishCommandOptions { preRelease?: boolean checkRemoteVersion?: boolean + npmTag?: string } -export async function publish({ preRelease, checkRemoteVersion }: PublishCommandOptions) { + +export async function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions) { const s = createSpinner('Publishing all packages').start() const args = ['-r', 'publish', '--no-git-checks', '--access', 'public'] @@ -47,6 +49,10 @@ export async function publish({ preRelease, checkRemoteVersion }: PublishCommand args.push('--tag', 'alpha') } + if (npmTag) { + args.push('--tag', npmTag) + } + const ret = await execa('pnpm', args) if (ret.stderr && ret.stderr.includes('npm ERR!')) { throw new Error('\n' + ret.stderr) @@ -156,6 +162,7 @@ async function getReleaseType(): Promise { export interface ReleaseCommandOptions { remote?: string + npmTag?: string skipNpmPublish?: boolean skipChangelog?: boolean skipGitTag?: boolean @@ -200,7 +207,7 @@ export async function release(options: ReleaseCommandOptions) { } if (!options.skipNpmPublish) { - await publish({ preRelease: isPreRelease }) + await publish({ preRelease: isPreRelease, npmTag: options.npmTag }) } if (!isPreRelease) {