Skip to content

Commit

Permalink
feat: support npmTag
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Feb 19, 2024
1 parent ba2d189 commit 74a0c9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \<npmTag\> | npm tag |

#### changelog

Expand All @@ -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 \<npmTag\> | npm tag |

### Custom Handle

Expand Down Expand Up @@ -124,14 +126,16 @@ release({ task })
interface PublishCommandOptions {
preRelease?: boolean
checkRemoteVersion?: boolean
npmTag?: string
}
function publish({ preRelease, checkRemoteVersion }: PublishCommandOptions): Promise<void>
function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>
function updateVersion(version: string): void
interface ReleaseCommandOptions {
remote?: string
skipNpmPublish?: boolean
skipChangelog?: boolean
skipGitTag?: boolean
npmTag?: string
task?(): Promise<void>
}
function release(options: ReleaseCommandOptions): Promise<void>
Expand Down
6 changes: 5 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ npx vr publish
| -s --skip-npm-publish | 跳过 npm 发布 |
| -sc --skip-changelog | 跳过生成变更日志 |
| -sgt --skip-git-tag | 跳过 git tag |
| -nt --npm-tag \<npmTag\> | npm tag |

#### changelog

Expand All @@ -93,6 +94,7 @@ npx vr publish
| 参数 | 说明 |
| ------------------------- | --------------------------------------------------------------------- |
| -c --check-remote-version | 检测npm包的远程版本是否与要在本地发布的包版本相同,如果是,则跳过发布 |
| -nt --npm-tag \<npmTag\> | npm tag |

### 自定义处理

Expand Down Expand Up @@ -124,14 +126,16 @@ release({ task })
interface PublishCommandOptions {
preRelease?: boolean
checkRemoteVersion?: boolean
npmTag?: string
}
function publish({ preRelease, checkRemoteVersion }: PublishCommandOptions): Promise<void>
function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>
function updateVersion(version: string): void
interface ReleaseCommandOptions {
remote?: string
skipNpmPublish?: boolean
skipChangelog?: boolean
skipGitTag?: boolean
npmTag?: string
task?(): Promise<void>
}
function release(options: ReleaseCommandOptions): Promise<void>
Expand Down
2 changes: 2 additions & 0 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <npmTag>', '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 <npmTag>', 'Npm tag')
.description('Publish to npm')
.action(async (options) => publish(options))

Expand Down
13 changes: 10 additions & 3 deletions src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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)
Expand Down Expand Up @@ -156,6 +162,7 @@ async function getReleaseType(): Promise<ReleaseType> {

export interface ReleaseCommandOptions {
remote?: string
npmTag?: string
skipNpmPublish?: boolean
skipChangelog?: boolean
skipGitTag?: boolean
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 74a0c9a

Please sign in to comment.