mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-21 14:05:41 +00:00
99c78d8567
Extend sync-tauri-version-from-package.js to align psysonic* crate version fields in Cargo.lock with package.json. Include the lockfile in promote and post-release main-bump commits. Fixes drift where lock stayed on the previous -dev while Cargo.toml already matched the channel bump.
50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Align src-tauri/Cargo.toml, src-tauri/tauri.conf.json, and workspace entries in
|
|
* src-tauri/Cargo.lock with package.json "version".
|
|
* Used after npm version in promote workflows so bundle names match release semver.
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const root = path.join(__dirname, '..');
|
|
const version = require(path.join(root, 'package.json')).version;
|
|
if (!version || typeof version !== 'string') {
|
|
console.error('package.json version missing');
|
|
process.exit(1);
|
|
}
|
|
|
|
const cargoPath = path.join(root, 'src-tauri', 'Cargo.toml');
|
|
let cargo = fs.readFileSync(cargoPath, 'utf8');
|
|
if (!/^version = "[^"]*"$/m.test(cargo)) {
|
|
console.error('Cargo.toml: expected a package-level line: version = "..."');
|
|
process.exit(1);
|
|
}
|
|
cargo = cargo.replace(/^version = "[^"]*"$/m, `version = "${version}"`);
|
|
fs.writeFileSync(cargoPath, cargo);
|
|
console.log(`Cargo.toml -> ${version}`);
|
|
|
|
const confPath = path.join(root, 'src-tauri', 'tauri.conf.json');
|
|
const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
|
|
conf.version = version;
|
|
fs.writeFileSync(confPath, JSON.stringify(conf, null, 2) + '\n');
|
|
console.log(`tauri.conf.json -> ${version}`);
|
|
|
|
/** @param {string} lockText */
|
|
function syncCargoLockWorkspaceVersions(lockText, targetVersion) {
|
|
return lockText.replace(
|
|
/^(name = "psysonic[^"]*"\nversion = ")[^"]+"/gm,
|
|
`$1${targetVersion}"`,
|
|
);
|
|
}
|
|
|
|
const lockPath = path.join(root, 'src-tauri', 'Cargo.lock');
|
|
let lock = fs.readFileSync(lockPath, 'utf8');
|
|
const updatedLock = syncCargoLockWorkspaceVersions(lock, version);
|
|
if (updatedLock !== lock) {
|
|
fs.writeFileSync(lockPath, updatedLock);
|
|
console.log(`Cargo.lock workspace crates -> ${version}`);
|
|
} else {
|
|
console.log(`Cargo.lock workspace crates already at ${version}`);
|
|
}
|