chain-saasui
Version:
chain-saasui
52 lines (43 loc) • 1.99 kB
JavaScript
const fs = require('fs');
const { execSync } = require('child_process');
async function updateVersion() {
try {
// 1. 读取当前版本
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const currentVersion = packageJson.version;
const isAlphaVersion = currentVersion.includes('-alpha');
// 2. 执行构建
console.log('🚀 开始构建项目...');
execSync('npm run build:lib', { stdio: 'inherit' });
console.log('✅ 构建完成');
// 3. 更新版本
console.log('\n🔄 更新版本号...');
if (isAlphaVersion) {
console.log('当前是 alpha 版本,执行 prerelease');
execSync('npm version prerelease --preid=alpha', { stdio: 'inherit' });
} else {
console.log('当前不是 alpha 版本,执行 prepatch 并添加 alpha 后缀');
execSync('npm version prepatch --preid=alpha', { stdio: 'inherit' });
}
// 4. 获取新版本号
const updatedPackageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const newVersion = updatedPackageJson.version;
// 5. Git提交
console.log('\n💾 提交代码变更...');
execSync('git add .', { stdio: 'inherit' });
execSync(`git commit -m "release: v${newVersion}"`, { stdio: 'inherit' });
console.log('✅ 代码提交完成');
// 6. 发布到npm
console.log('\n📦 发布到npm...');
execSync('npm publish --access public', { stdio: 'inherit' });
console.log(`🎉 成功发布 v${newVersion} 到npm`);
// 7. 推送git标签
console.log('\n🏷️ 推送git标签...');
execSync('git push --follow-tags', { stdio: 'inherit' });
console.log('✅ 标签推送完成');
} catch (error) {
console.error('\n❌ 发布流程出错:', error.message);
process.exit(1);
}
}
updateVersion();