#!/usr/bin/env node 'use strict' // 统一改版本号:package.json / src-tauri/tauri.conf.json / src-tauri/Cargo.toml // 用法:node scripts/set-version.js 3.25.0 (三个文件必须一致,否则发布/更新判断会错) const fs = require('fs') const path = require('path') const root = path.resolve(__dirname, '..') const v = String(process.argv[2] || '').trim() if (!/^\d+\.\d+\.\d+/.test(v)) { console.error('用法: node scripts/set-version.js 3.25.0'); process.exit(1) } const pkgPath = path.join(root, 'package.json') const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')) pkg.version = v fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') const confPath = path.join(root, 'src-tauri', 'tauri.conf.json') const conf = JSON.parse(fs.readFileSync(confPath, 'utf8')) conf.version = v fs.writeFileSync(confPath, JSON.stringify(conf, null, 2) + '\n') const cargoPath = path.join(root, 'src-tauri', 'Cargo.toml') let cargo = fs.readFileSync(cargoPath, 'utf8') cargo = cargo.replace(/^version = "[^"]*"/m, 'version = "' + v + '"') fs.writeFileSync(cargoPath, cargo) console.log('版本已设为 ' + v + '(package.json / tauri.conf.json / Cargo.toml)') console.log('提示:改完记得提交,并在发版时打 tag;CHANGELOG 若维护也要同步。')