|
@@ -15,12 +15,18 @@ const isGitClean = () => {
|
|
return status === ''
|
|
return status === ''
|
|
}
|
|
}
|
|
|
|
|
|
-// 检查是否有符合规范的提交(feat、fix 等)
|
|
|
|
|
|
+// 检查是否有符合规范的提交
|
|
const hasConventionalCommits = () => {
|
|
const hasConventionalCommits = () => {
|
|
- const lastTag = execSync('git describe --tags --abbrev=0', { stdio: 'pipe' }).toString().trim()
|
|
|
|
- const log = execSync(`git log ${lastTag}..HEAD --pretty=format:%s`, { stdio: 'pipe' })
|
|
|
|
- .toString()
|
|
|
|
- .trim()
|
|
|
|
|
|
+ let lastTag = ''
|
|
|
|
+ try {
|
|
|
|
+ lastTag = execSync('git describe --tags --abbrev=0', { stdio: 'pipe' }).toString().trim()
|
|
|
|
+ } catch {
|
|
|
|
+ // 没有 tag 不影响
|
|
|
|
+ }
|
|
|
|
+ const logCmd = lastTag
|
|
|
|
+ ? `git log ${lastTag}..HEAD --pretty=format:%s`
|
|
|
|
+ : `git log --pretty=format:%s`
|
|
|
|
+ const log = execSync(logCmd, { stdio: 'pipe' }).toString().trim()
|
|
return /^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:/m.test(log)
|
|
return /^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?:/m.test(log)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -36,7 +42,7 @@ if (!isGitClean()) {
|
|
process.exit(1)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
|
|
-// 3. 检查是否有符合规范的提交
|
|
|
|
|
|
+// 3. 检查提交规范
|
|
if (!hasConventionalCommits()) {
|
|
if (!hasConventionalCommits()) {
|
|
console.error('⚠️ 没有检测到符合 Angular 提交规范的提交,跳过 changelog 生成!')
|
|
console.error('⚠️ 没有检测到符合 Angular 提交规范的提交,跳过 changelog 生成!')
|
|
process.exit(1)
|
|
process.exit(1)
|
|
@@ -58,39 +64,16 @@ const { mode } = await inquirer.prompt([
|
|
|
|
|
|
// 5. 生成 changelog
|
|
// 5. 生成 changelog
|
|
if (mode === 'all') {
|
|
if (mode === 'all') {
|
|
|
|
+ console.log('📝 正在全量生成 changelog...')
|
|
|
|
+ fs.writeFileSync(changelogPath, '', 'utf-8') // 先清空
|
|
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 {
|
|
|
|
+ console.log('📝 正在追加 changelog...')
|
|
run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
|
|
run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
|
|
}
|
|
}
|
|
|
|
|
|
-// 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' },
|
|
|
|
- ],
|
|
|
|
- },
|
|
|
|
-])
|
|
|
|
-
|
|
|
|
-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"`)
|
|
|
|
-}
|
|
|
|
|
|
+// 6. 更新版本号(补丁版本)
|
|
|
|
+run('npm version patch -m "new version published: v%s"')
|
|
|
|
|
|
// 7. 推送代码和 tag
|
|
// 7. 推送代码和 tag
|
|
run('git push && git push --tags')
|
|
run('git push && git push --tags')
|