Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@142vip/release-version): 新增scopeName可选参数,支持在Monorepo模式下发布子模块版本、更新CHANGELOG文档 #39

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/release-version/src/core/normalize-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface NormalizedOptions {
customVersion?: VersionBumpOptions['customVersion']
currentVersion?: string
changelog?: boolean
// monorepo 模块名
scopeName?: string
}

/**
Expand All @@ -81,6 +83,8 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
const execute = raw.execute
const recursive = Boolean(raw.recursive)
const changelog = Boolean(raw.changelog)
// 允许用户不输入
const scopeName = raw.scopeName ?? undefined

let release: Release
if (!raw.release || raw.release === 'prompt')
Expand Down Expand Up @@ -182,5 +186,6 @@ export async function normalizeOptions(raw: VersionBumpOptions): Promise<Normali
customVersion: raw.customVersion,
currentVersion: raw.currentVersion,
changelog,
scopeName,
}
}
6 changes: 5 additions & 1 deletion packages/release-version/src/core/version-bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export async function versionBump(arg: (VersionBumpOptions) | string = {}): Prom
if (operation.options.changelog) {
console.log(symbols.info, 'Generate CHANGELOG.md By @142vip/changelog', operation.options.execute)
try {
await execShell({ command: `changelog --output CHANGELOG.md --name v${operation.state.newVersion}`, description: '生成CHANGELOG文档' })
const baseCommand = `changelog --output CHANGELOG.md --name v${operation.state.newVersion}`
// 支持monorepo子模块
await execShell(operation.options.scopeName != null
? { command: `${baseCommand} --scopeName ${operation.options.scopeName}`, description: `MonoRepo模式,生成${operation.options.scopeName}模块的CHANGELOG文档` }
: { command: baseCommand, description: '普通模式,生成CHANGELOG文档' })
}
catch (e) {
console.log(symbols.error, 'Happen Error In Generate CHANGELOG!!!')
Expand Down
7 changes: 6 additions & 1 deletion packages/release-version/src/types/version-bump-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,15 @@ export interface VersionBumpOptions {
progress?: (progress: VersionBumpProgress) => void

/**
* Excute additional command after bumping and before commiting
* Execute additional command after bumping and before commiting
*/
execute?: string

/**
* monorepo package name
*/
scopeName?: string

/**
* Bump the files recursively for monorepo. Only works without `files` option.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/release-version/src/utils/parse-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export async function parseArgs(): Promise<ParsedArgs> {
execute: args.execute,
recursive: !!args.recursive,
changelog: !!args.changelog,
scopeName: args.scopeName,
}),
}

Expand Down Expand Up @@ -87,6 +88,7 @@ export function loadCliArgs(argv = process.argv) {
.option('--changelog', 'generate CHANGELOG.md', { default: false })
.option('-v, --version <version>', 'Target version')
.option('--current-version <version>', 'Current version')
.option('--scopeName <scopeName>', 'Package name in monorepo')
.option('-x, --execute <command>', 'Commands to execute after version bumps')
.help()

Expand Down
Loading