123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/usr/bin/env node
- import { execSync } from 'child_process'
- import inquirer from 'inquirer'
- import fs from 'fs'
- function run(cmd) {
- execSync(cmd, { stdio: 'inherit' })
- }
- function getVersion() {
- return JSON.parse(fs.readFileSync('package.json', 'utf8')).version
- }
- async function main() {
- console.log('🚀 开始发布流程...')
- // 1. 选择版本类型
- const { versionType } = await inquirer.prompt([
- {
- type: 'list',
- name: 'versionType',
- message: '请选择版本类型:',
- choices: [
- { name: '补丁版本 (patch)', value: 'patch' },
- { name: '小版本 (minor)', value: 'minor' },
- { name: '大版本 (major)', value: 'major' },
- ],
- },
- ])
- // 2. 选择日志生成模式
- const { changelogMode } = await inquirer.prompt([
- {
- type: 'list',
- name: 'changelogMode',
- message: '请选择 changelog 生成模式:',
- choices: [
- { name: '全量生成(会覆盖整个文件)', value: 'full' },
- { name: '增量生成(只追加本次更新的内容)', value: 'incremental' },
- ],
- },
- ])
- // 3. 根据模式生成 changelog
- console.log('📝 正在生成 changelog...')
- if (changelogMode === 'full') {
- run('npx conventional-changelog -p angular -i CHANGELOG.md -s -r 0')
- } else {
- run('npx conventional-changelog -p angular -i CHANGELOG.md -s')
- }
- // 4. 提交 changelog
- run('git add CHANGELOG.md')
- run('git commit -m "chore: update changelog"')
- // 5. 更新版本号并生成 tag(会合并 changelog 提交)
- run(`npm version ${versionType} -m "new version published: v%s"`)
- const version = getVersion()
- // 6. 推送代码 & tag
- run('git push --follow-tags')
- // 7. 彩色提示
- console.log('\x1b[36m=========================\x1b[0m')
- console.log('\x1b[32m🎉 发布成功!\x1b[0m')
- console.log(`\x1b[33m📦 版本号:v${version}\x1b[0m`)
- console.log('\x1b[35m⚙️ 部署:\x1b[0m')
- console.log('\x1b[34m * 测试环境:npm run deploy:test\x1b[0m')
- console.log('\x1b[34m * 开发环境:npm run build:dev\x1b[0m')
- console.log('\x1b[34m * 生产环境:npm run build\x1b[0m')
- console.log('\x1b[36m=========================\x1b[0m')
- }
- main()
|