diff --git a/README.md b/README.md index b8017ae..4f2e96f 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ npx vr changelog --file changelog.md # Lint commit message npx vr lint-commit -p .git/COMMIT_EDITMSG + +# Publish to npm, which can be called in the ci environment +npx vr publish ``` ### Configuration @@ -71,6 +74,7 @@ npx vr lint-commit -p .git/COMMIT_EDITMSG | Params | Instructions | | ----------------------------------- | -------------------------- | | -f --file \ | Specify changelog filename | +| -s --skip-npm-publish | Skip npm publish | | -rc --releaseCount \ | Release count | #### lint-commit @@ -82,6 +86,12 @@ npx vr lint-commit -p .git/COMMIT_EDITMSG | -e --errorMessage \ | Validation failed to display error messages | | -w --warningMessage \ | Validation failed to display warning messages | +#### publish + +```shell +vr publish +``` + ### Custom Handle #### Example @@ -109,8 +119,11 @@ release({ task }) #### Types ```ts +function publish(preRelease: boolean | undefined): Promise +function updateVersion(version: string): void interface ReleaseCommandOptions { remote?: string + skipNpmPublish?: boolean task?(): Promise } function release(options: ReleaseCommandOptions): Promise @@ -121,6 +134,9 @@ interface ChangelogCommandOptions { } function changelog({ releaseCount, file }?: ChangelogCommandOptions): Promise +const COMMIT_MESSAGE_RE: RegExp +function isVersionCommitMessage(message: string): string | false | null +function getCommitMessage(commitMessagePath: string): string interface CommitLintCommandOptions { commitMessagePath: string commitMessageRe?: string | RegExp diff --git a/README.zh-CN.md b/README.zh-CN.md index 414de8f..43a5195 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -56,6 +56,9 @@ npx vr changelog --file changelog.md # 检测 commit message npx vr lint-commit -p .git/COMMIT_EDITMSG + +# 发布到 npm,可以在 ci 中执行 +npx vr publish ``` ### 配置 @@ -71,6 +74,7 @@ npx vr lint-commit -p .git/COMMIT_EDITMSG | 参数 | 说明 | | ----------------------------------- | ------------------ | | -f --file \ | 指定变更日志文件名 | +| -s --skip-npm-publish | 跳过 npm 发布 | | -rc --releaseCount \ | 发布数量 | #### lint-commit @@ -82,6 +86,12 @@ npx vr lint-commit -p .git/COMMIT_EDITMSG | -e --errorMessage \ | 验证失败展示的错误信息 | | -w --warningMessage \ | 验证失败展示的提示信息 | +#### publish + +```shell +vr publish +``` + ### 自定义处理 #### 示例 @@ -109,8 +119,11 @@ release({ task }) #### 类型 ```ts +function publish(preRelease: boolean | undefined): Promise +function updateVersion(version: string): void interface ReleaseCommandOptions { remote?: string + skipNpmPublish?: boolean task?(): Promise } function release(options: ReleaseCommandOptions): Promise @@ -121,6 +134,9 @@ interface ChangelogCommandOptions { } function changelog({ releaseCount, file }?: ChangelogCommandOptions): Promise +const COMMIT_MESSAGE_RE: RegExp +function isVersionCommitMessage(message: string): string | false | null +function getCommitMessage(commitMessagePath: string): string interface CommitLintCommandOptions { commitMessagePath: string commitMessageRe?: string | RegExp diff --git a/bin/index.js b/bin/index.js index 61e25a4..844a491 100644 --- a/bin/index.js +++ b/bin/index.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { release, changelog, commitLint } from '../dist/index.js' +import { release, publish, changelog, commitLint } from '../dist/index.js' import { Command } from 'commander' const program = new Command() @@ -7,9 +7,15 @@ const program = new Command() program .command('release') .option('-r --remote ', 'Remote name') + .option('-s --skip-npm-publish', 'Skip npm publish') .description('Release all packages and generate changelogs') .action(async (options) => release(options)) +program + .command('publish') + .description('Publish to npm') + .action(async () => publish()) + program .command('changelog') .option('-rc --releaseCount ', 'Release count') diff --git a/src/release.ts b/src/release.ts index dedc5a1..589fc2e 100644 --- a/src/release.ts +++ b/src/release.ts @@ -19,7 +19,7 @@ async function isWorktreeEmpty() { return !ret.stdout } -async function publish(preRelease: boolean) { +export async function publish(preRelease: boolean | undefined) { const s = createSpinner('Publishing all packages').start() const args = ['-r', 'publish', '--no-git-checks', '--access', 'public'] @@ -48,7 +48,7 @@ async function pushGit(version: string, remote = 'origin') { ret.stdout && logger.info(ret.stdout) } -function updateVersion(version: string) { +export function updateVersion(version: string) { const packageJsons = glob.sync('packages/*/package.json') packageJsons.push('package.json') @@ -121,6 +121,7 @@ async function getReleaseType() { export interface ReleaseCommandOptions { remote?: string + skipNpmPublish?: boolean task?(): Promise } @@ -161,7 +162,9 @@ export async function release(options: ReleaseCommandOptions) { await options.task() } - await publish(isPreRelease) + if (!options.skipNpmPublish) { + await publish(isPreRelease) + } if (!isPreRelease) { await changelog() @@ -173,11 +176,15 @@ export async function release(options: ReleaseCommandOptions) { if (isPreRelease) { try { await execa('git', ['restore', '**/package.json']) - } catch { /* empty */ } + } catch { + /* empty */ + } try { await execa('git', ['restore', 'package.json']) - } catch { /* empty */ } + } catch { + /* empty */ + } } } catch (error: any) { logger.error(error.toString())