|
@@ -36,27 +36,13 @@ if (!isGitClean()) {
|
|
process.exit(1)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
|
|
-// 3. 询问发布模式
|
|
|
|
-const { publishMode } = await inquirer.prompt([
|
|
|
|
- {
|
|
|
|
- type: 'list',
|
|
|
|
- name: 'publishMode',
|
|
|
|
- message: '请选择发布模式:',
|
|
|
|
- choices: [
|
|
|
|
- { name: '正常发版(更新版本号并推送)', value: 'normal' },
|
|
|
|
- { name: '自测模式(仅生成 changelog,不推送)', value: 'test' },
|
|
|
|
- ],
|
|
|
|
- default: 'normal',
|
|
|
|
- },
|
|
|
|
-])
|
|
|
|
-
|
|
|
|
-// 4. 检查是否有符合规范的提交
|
|
|
|
|
|
+// 3. 检查是否有符合规范的提交
|
|
if (!hasConventionalCommits()) {
|
|
if (!hasConventionalCommits()) {
|
|
console.error('⚠️ 没有检测到符合 Angular 提交规范的提交,跳过 changelog 生成!')
|
|
console.error('⚠️ 没有检测到符合 Angular 提交规范的提交,跳过 changelog 生成!')
|
|
process.exit(1)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
|
|
-// 5. 询问生成 changelog 的方式
|
|
|
|
|
|
+// 4. 询问生成 changelog 的方式
|
|
const { mode } = await inquirer.prompt([
|
|
const { mode } = await inquirer.prompt([
|
|
{
|
|
{
|
|
type: 'list',
|
|
type: 'list',
|
|
@@ -70,23 +56,43 @@ const { mode } = await inquirer.prompt([
|
|
},
|
|
},
|
|
])
|
|
])
|
|
|
|
|
|
-// 6. 生成 changelog
|
|
|
|
|
|
+// 5. 生成 changelog
|
|
if (mode === 'all') {
|
|
if (mode === 'all') {
|
|
run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
|
|
run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
|
|
} else {
|
|
} else {
|
|
run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
|
|
run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
|
|
}
|
|
}
|
|
|
|
|
|
-// 7. 如果是自测模式,提前结束
|
|
|
|
-if (publishMode === 'test') {
|
|
|
|
- console.log('✅ 自测模式完成(未生成 tag / 未推送)')
|
|
|
|
- process.exit(0)
|
|
|
|
-}
|
|
|
|
|
|
+// 6. 选择版本号类型
|
|
|
|
+const { versionType } = await inquirer.prompt([
|
|
|
|
+ {
|
|
|
|
+ type: 'list',
|
|
|
|
+ name: 'versionType',
|
|
|
|
+ message: '请选择版本号更新类型:',
|
|
|
|
+ choices: [
|
|
|
|
+ { name: '补丁版本 (patch)', value: 'patch' },
|
|
|
|
+ { name: '小版本 (minor)', value: 'minor' },
|
|
|
|
+ { name: '大版本 (major)', value: 'major' },
|
|
|
|
+ { name: '自定义版本', value: 'custom' },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+])
|
|
|
|
|
|
-// 8. 更新版本号(补丁版本)
|
|
|
|
-run('npm version patch -m "new version published: v%s"')
|
|
|
|
|
|
+if (versionType === 'custom') {
|
|
|
|
+ const { customVersion } = await inquirer.prompt([
|
|
|
|
+ {
|
|
|
|
+ type: 'input',
|
|
|
|
+ name: 'customVersion',
|
|
|
|
+ message: '请输入自定义版本号(例如 1.2.3):',
|
|
|
|
+ validate: (input) => /^\d+\.\d+\.\d+$/.test(input) || '版本号格式不正确,请输入 x.y.z',
|
|
|
|
+ },
|
|
|
|
+ ])
|
|
|
|
+ run(`npm version ${customVersion} -m "new version published: v%s"`)
|
|
|
|
+} else {
|
|
|
|
+ run(`npm version ${versionType} -m "new version published: v%s"`)
|
|
|
|
+}
|
|
|
|
|
|
-// 9. 推送代码和 tag
|
|
|
|
|
|
+// 7. 推送代码和 tag
|
|
run('git push && git push --tags')
|
|
run('git push && git push --tags')
|
|
|
|
|
|
console.log('✅ 发布完成!')
|
|
console.log('✅ 发布完成!')
|