chore: ✏️ 升级版本+升级版本的脚本
This commit is contained in:
58
build/updateVersion.js
Normal file
58
build/updateVersion.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
// 从命令行参数获取版本号
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
let version = args[0];
|
||||||
|
|
||||||
|
if (!version) {
|
||||||
|
console.error('错误: 请提供版本号作为参数');
|
||||||
|
console.error('用法: node build/updateVersion.js <version>');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证版本号格式 (遵循语义化版本号格式,如 x.y.z)
|
||||||
|
const versionRegex = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/;
|
||||||
|
if (!versionRegex.test(version)) {
|
||||||
|
console.error(`错误: 版本号格式不正确: ${version}`);
|
||||||
|
console.error('正确的版本号格式示例: 1.0.0, 2.1.3, 0.5.0-beta 等');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新 package.json
|
||||||
|
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||||
|
packageJson.version = version;
|
||||||
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
||||||
|
|
||||||
|
// 读取并更新 tauri.conf.json
|
||||||
|
const tauriConfPath = path.join(__dirname, '..', 'src-tauri', 'tauri.conf.json');
|
||||||
|
const tauriConf = JSON.parse(fs.readFileSync(tauriConfPath, 'utf8'));
|
||||||
|
|
||||||
|
// 更新版本号
|
||||||
|
tauriConf.version = version;
|
||||||
|
|
||||||
|
// 写回 tauri.conf.json
|
||||||
|
fs.writeFileSync(tauriConfPath, JSON.stringify(tauriConf, null, 2));
|
||||||
|
|
||||||
|
// 读取并更新 Cargo.toml
|
||||||
|
const cargoTomlPath = path.join(__dirname, '..', 'src-tauri', 'Cargo.toml');
|
||||||
|
let cargoToml = fs.readFileSync(cargoTomlPath, 'utf8');
|
||||||
|
|
||||||
|
// 使用正则表达式替换版本号
|
||||||
|
cargoToml = cargoToml.replace(
|
||||||
|
/^(\s*version\s*=\s*["'])([^"']*)(["']\s*)$/m,
|
||||||
|
`$1${version}$3`
|
||||||
|
);
|
||||||
|
|
||||||
|
// 写回 Cargo.toml
|
||||||
|
fs.writeFileSync(cargoTomlPath, cargoToml);
|
||||||
|
|
||||||
|
console.log(`版本号已更新至: ${version}`);
|
||||||
|
console.log(`- package.json`);
|
||||||
|
console.log(`- tauri.conf.json`);
|
||||||
|
console.log(`- Cargo.toml`);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "log-lottery",
|
"name": "log-lottery",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.5.0",
|
"version": "0.5.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
"build:pre": "vue-tsc --noEmit && vite build --mode prebuild",
|
"build:pre": "vue-tsc --noEmit && vite build --mode prebuild",
|
||||||
"build:file": "vue-tsc --noEmit && vite build --mode file",
|
"build:file": "vue-tsc --noEmit && vite build --mode file",
|
||||||
"tauri": "node ./build/syncVersion.js && tauri",
|
"tauri": "node ./build/syncVersion.js && tauri",
|
||||||
|
"update-version": "node ./build/updateVersion.js",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"test:ui": "vitest --ui",
|
"test:ui": "vitest --ui",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "app"
|
name = "app"
|
||||||
version = "0.5.0"
|
version = "0.5.2"
|
||||||
description = "A Tauri App"
|
description = "A Tauri App"
|
||||||
authors = ["you"]
|
authors = ["you"]
|
||||||
license = ""
|
license = ""
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
|
||||||
"productName": "log-lottery",
|
"productName": "log-lottery",
|
||||||
"version": "0.5.0",
|
"version": "0.5.2",
|
||||||
"identifier": "to2026.xyz",
|
"identifier": "to2026.xyz",
|
||||||
"build": {
|
"build": {
|
||||||
"frontendDist": "../dist",
|
"frontendDist": "../dist",
|
||||||
|
|||||||
Reference in New Issue
Block a user