Files
Rosea/scripts/check-version.mjs

39 lines
1.7 KiB
JavaScript

// The release tag and the version files must agree (.agents/features/fabrica-release.md F10).
// Fabrica's Deploy runs `node scripts/check-version.mjs <version>` and rewrites exactly the files it names;
// each line is Fabrica's contract: `<file> says <old>, the tag says <new>` (Fabrica docs/04_deploy.md).
// The installer and the APK take their version from apps/rosea/package.json (tauri.conf.json reads it).
import { readFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
/** Every file that carries the app's version, relative to the repository root. */
export const VERSION_FILES = [
'package.json',
'apps/rosea/package.json',
'apps/rosea-tauri/package.json',
'apps/rosea-tauri/src-tauri/Cargo.toml'
];
function versionOf(root, file) {
const text = readFileSync(join(root, file), 'utf8');
if (file.endsWith('.toml')) return text.match(/^version = "([^"]+)"/m)?.[1];
return JSON.parse(text).version;
}
/** The lines to print, one per file whose version is not `want`. Empty when they all agree. */
export function versionProblems(root, want) {
if (!want) return ['usage: node scripts/check-version.mjs <version>'];
return VERSION_FILES.map((f) => [f, versionOf(root, f)])
.filter(([, v]) => v !== want)
.map(([f, v]) => `${f} says ${v}, the tag says ${want}`);
}
const isMain = (arg) => Boolean(arg) && resolve(arg).toLowerCase() === fileURLToPath(import.meta.url).toLowerCase();
if (isMain(process.argv[1])) {
const want = process.argv[2]?.replace(/^v/, '');
const problems = versionProblems(fileURLToPath(new URL('..', import.meta.url)), want);
for (const p of problems) console.error(p);
if (problems.length > 0) process.exit(1);
console.log(`version ${want} everywhere`);
}