44 lines
1.8 KiB
JavaScript
44 lines
1.8 KiB
JavaScript
// SPDX-License-Identifier: CPAL-1.0
|
|
// Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution
|
|
// License 1.0: see LICENSE (its Exhibit A is this file's notice).
|
|
|
|
// The release's version check (docs/release.md): every place that carries Ianitor's version agrees,
|
|
// and, given a version (the tag's, e.g. 0.1.0 for v0.1.0), is that version.
|
|
// node scripts/check-version.mjs [X.Y.Z]
|
|
// Exit codes: 0 they agree, 1 they do not, 2 usage.
|
|
|
|
import { readFileSync } from "node:fs";
|
|
import { dirname, join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const repo = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
const want = process.argv[2];
|
|
if (process.argv.length > 3 || (want !== undefined && !/^\d+\.\d+\.\d+$/.test(want))) {
|
|
console.error("usage: node scripts/check-version.mjs [X.Y.Z]");
|
|
process.exit(2);
|
|
}
|
|
|
|
function cargo() {
|
|
const text = readFileSync(join(repo, "Cargo.toml"), "utf8");
|
|
const section = /^\[workspace\.package\]\s*$([\s\S]*?)(?=^\[|(?![\s\S]))/m.exec(text);
|
|
const v = section && /^version\s*=\s*"([^"]*)"\s*$/m.exec(section[1]);
|
|
return v ? v[1] : null;
|
|
}
|
|
|
|
const pkg = (p) => JSON.parse(readFileSync(join(repo, p), "utf8")).version ?? null;
|
|
|
|
const found = [
|
|
["Cargo.toml [workspace.package]", cargo()],
|
|
["apps/web/package.json", pkg("apps/web/package.json")],
|
|
["packages/ui/package.json", pkg("packages/ui/package.json")],
|
|
];
|
|
|
|
const expected = want ?? found[0][1];
|
|
const wrong = found.filter(([, v]) => v !== expected);
|
|
for (const [where, v] of found) console.log(`${where}: ${v ?? "(none)"}`);
|
|
if (wrong.length) {
|
|
console.error(`version: expected ${expected} everywhere; ${wrong.map(([w, v]) => `${w} has ${v ?? "none"}`).join(", ")}`);
|
|
process.exit(1);
|
|
}
|
|
console.log(`version: ${expected} everywhere`);
|