Files
koring-launcher/scripts/version.js
T
dream_pep 4d3e43394c feat(auto-update): 实现全流程自动更新功能与配套界面
- 新增主进程更新服务,支持GitHub官方源与加速源兜底的检查、下载、安装全流程
- 新增独立更新日志页面,支持查看更新说明与更新全流程管理
- 实现更新状态持久化,重启应用可恢复上次未完成的下载进度
- 完善版本管理与构建元数据脚本,优化CI发布流水线
- 补充VersionCard的构建信息展示与更新页跳转逻辑
- 新增更新相关IPC接口、类型定义与全局状态管理
- 清理旧的无用配置项,升级相关依赖包
2026-08-30 20:19:15 +08:00

83 lines
2.7 KiB
JavaScript
Raw Permalink 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.
const { readFileSync, writeFileSync } = require('fs');
const { join } = require('path');
const root = join(__dirname, '..');
const pkgPath = join(root, 'package.json');
function getCurrentVersion() {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
return pkg.version;
}
/** 仅写文件,不打印(stdout 纯净,供脚本/CI 捕获) */
function setVersion(version) {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
pkg.version = version;
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
}
// Parse args
const args = process.argv.slice(2);
if (args.length === 0) {
console.log(`Current version: ${getCurrentVersion()}`);
process.exit(0);
}
// 输出裸版本号(供脚本/CI 使用)
if (args[0] === 'get') {
console.log(getCurrentVersion());
process.exit(0);
}
// 构建版本:统一「base + 构建号」规则,消除本地/CI 版本双轨
// version.js build ci [buildId] [base] CIbase 缺省读 package.json → 设置并输出 base-buildId
// version.js build local 本地:输出当前 base(不修改)
if (args[0] === 'build') {
const kind = args[1];
if (kind === 'ci') {
const buildId = args[2] || process.env.GITHUB_RUN_NUMBER || '0';
const base = args[3] || getCurrentVersion();
const full = `${base}-${buildId}`;
setVersion(full);
console.log(full); // stdout 仅版本号
process.exit(0);
}
if (kind === 'local') {
console.log(getCurrentVersion());
process.exit(0);
}
console.error('Usage: node scripts/version.js build ci [buildId] [base] | node scripts/version.js build local');
process.exit(1);
}
if (args[0] === '--help' || args[0] === '-h') {
console.log('Usage:');
console.log(' node scripts/version.js <version> Set version');
console.log(' node scripts/version.js Show current version');
console.log(' node scripts/version.js get Print raw version');
console.log(' node scripts/version.js build ci [buildId] [base] CI build version (base-buildId)');
console.log(' node scripts/version.js build local Print local base version');
console.log('');
console.log('Examples:');
console.log(' node scripts/version.js 1.0.0');
console.log(' node scripts/version.js 1.1.0-beta.1');
console.log(' node scripts/version.js build ci 12');
process.exit(0);
}
const newVersion = args[0];
// Validate semver-ish format
if (!/^\d+\.\d+\.\d+/.test(newVersion)) {
console.error(`Invalid version: ${newVersion}`);
console.error('Expected format: x.y.z or x.y.z-tag');
process.exit(1);
}
const current = getCurrentVersion();
console.log(`Current version: ${current}`);
setVersion(newVersion);
console.log(`Version updated to ${newVersion}`);
console.log(' - package.json');