Files
echo/scripts/release.cjs

46 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 自定义发布脚本:接管 npm version + Android 版本同步 + git 提交与打 tag */
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const rootDir = path.resolve(__dirname, '..')
const run = (cmd) => {
console.log(`[release] ${cmd}`)
execSync(cmd, { stdio: 'inherit', cwd: rootDir })
}
const readJson = (file) =>
JSON.parse(fs.readFileSync(path.join(rootDir, file), 'utf8'))
const main = () => {
const type = process.argv[2] || 'patch' // patch / minor / major
// 1仅更新 version 字段,不让 npm 自动 commit / tag.npmrc 已全局禁止,但这里再显式加一层保险)
run(`npm version ${type} --no-git-tag-version`)
// 2同步 Android 版本versionCode / versionName
run('npm run version:sync')
// 3读取新版本号
const pkg = readJson('package.json')
const version = pkg.version
// 4只提交与版本相关的文件避免误提交其它开发中的改动
const filesToAdd = [
'package.json',
'package-lock.json',
'android/app/build.gradle',
]
run(`git add ${filesToAdd.join(' ')}`)
// 5提交并打 tag
run(`git commit -m "chore: release v${version}"`)
run(`git tag v${version}`)
console.log(`[release] 完成: v${version}`)
}
main()