Open History to see the last commit
1const fs = require("node:fs");
2
3// The manifests in scripts/lib/tagged-source-version.ts.
4const RELEASE_PACKAGE_FILES = [
5 "apps/server/package.json",
6 "apps/desktop/package.json",
7 "apps/web/package.json",
8 "packages/contracts/package.json",
9];
10const VERSION_LINE = /^( {2}"version": ")[^"]*(",?)$/gm;
11
12// Replaces one string literal, so the result needs no formatter and no dependencies.
13function setReleaseVersion(source, version) {
14 if (!/^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$/.test(version)) {
15 throw new Error(`Invalid release version: '${version}'.`);
16 }
17 if (source.match(VERSION_LINE)?.length !== 1) {
18 throw new Error("Expected exactly one top-level version in the manifest");
19 }
20 return source.replace(VERSION_LINE, `$1${version}$2`);
21}
22
23if (require.main === module) {
24 for (const file of RELEASE_PACKAGE_FILES) {
25 const source = fs.readFileSync(file, "utf8");
26 const next = setReleaseVersion(source, process.argv[2] ?? "");
27 if (next !== source) fs.writeFileSync(file, next);
28 }
29}
30
31module.exports = { RELEASE_PACKAGE_FILES, setReleaseVersion };