feat: auto-increment version number on build
This commit is contained in:
parent
568ce93bf0
commit
3e35258dd0
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "easyshell",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "跨平台远程Shell管理终端 - 支持 Windows/Mac/Linux/Android",
|
||||
"author": "EasyShell Team",
|
||||
"main": "main.js",
|
||||
@ -11,7 +11,12 @@
|
||||
"build": "react-scripts build",
|
||||
"electron": "electron .",
|
||||
"pack": "electron-builder --dir",
|
||||
"dist": "npm run icons && npm run build && electron-builder",
|
||||
"dist": "npm run version:patch && npm run icons && npm run build && electron-builder",
|
||||
"dist:minor": "npm run version:minor && npm run icons && npm run build && electron-builder",
|
||||
"dist:major": "npm run version:major && npm run icons && npm run build && electron-builder",
|
||||
"version:patch": "node scripts/bump-version.js patch",
|
||||
"version:minor": "node scripts/bump-version.js minor",
|
||||
"version:major": "node scripts/bump-version.js major",
|
||||
"icons": "node scripts/generate-icons.js",
|
||||
"server": "cd server && npm start",
|
||||
"server:dev": "cd server && npm run dev",
|
||||
|
||||
63
scripts/bump-version.js
Normal file
63
scripts/bump-version.js
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 自动更新版本号脚本
|
||||
* 每次打包时自动递增补丁版本号 (1.0.0 -> 1.0.1)
|
||||
*
|
||||
* 使用方式:
|
||||
* node scripts/bump-version.js # 递增补丁版本 (patch)
|
||||
* node scripts/bump-version.js minor # 递增次版本 (minor)
|
||||
* node scripts/bump-version.js major # 递增主版本 (major)
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// 获取版本类型参数
|
||||
const versionType = process.argv[2] || 'patch';
|
||||
|
||||
// 读取 package.json
|
||||
const packagePath = path.join(__dirname, '..', 'package.json');
|
||||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
||||
|
||||
// 解析当前版本
|
||||
const currentVersion = packageJson.version;
|
||||
const [major, minor, patch] = currentVersion.split('.').map(Number);
|
||||
|
||||
// 计算新版本
|
||||
let newVersion;
|
||||
switch (versionType) {
|
||||
case 'major':
|
||||
newVersion = `${major + 1}.0.0`;
|
||||
break;
|
||||
case 'minor':
|
||||
newVersion = `${major}.${minor + 1}.0`;
|
||||
break;
|
||||
case 'patch':
|
||||
default:
|
||||
newVersion = `${major}.${minor}.${patch + 1}`;
|
||||
break;
|
||||
}
|
||||
|
||||
// 更新 package.json
|
||||
packageJson.version = newVersion;
|
||||
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 4) + '\n', 'utf8');
|
||||
|
||||
// 输出结果
|
||||
console.log(`📦 版本号已更新: ${currentVersion} -> ${newVersion}`);
|
||||
|
||||
// 可选:更新其他需要版本号的文件
|
||||
// 例如更新 App 中显示的版本号
|
||||
|
||||
// 更新 TitleBar 组件中的版本号(如果存在硬编码)
|
||||
const titleBarPath = path.join(__dirname, '..', 'src', 'components', 'TitleBar.js');
|
||||
if (fs.existsSync(titleBarPath)) {
|
||||
let titleBarContent = fs.readFileSync(titleBarPath, 'utf8');
|
||||
// 匹配多种版本号格式: v1.0, v1.0.0, V1.0, V1.0.0
|
||||
const versionRegex = /[vV]\d+\.\d+(\.\d+)?/g;
|
||||
if (versionRegex.test(titleBarContent)) {
|
||||
titleBarContent = titleBarContent.replace(versionRegex, `V${newVersion}`);
|
||||
fs.writeFileSync(titleBarPath, titleBarContent, 'utf8');
|
||||
console.log(`📝 TitleBar.js 版本号已更新`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`✅ 版本更新完成!新版本: ${newVersion}`);
|
||||
@ -61,7 +61,7 @@ function TitleBar() {
|
||||
</span>
|
||||
{/* 版本徽章 */}
|
||||
<span className="badge-cyber text-shell-accent">
|
||||
v1.0
|
||||
V1.0.1
|
||||
</span>
|
||||
</div>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user