Skip to content

Commit d3509fb

Browse files
flevi29Strift
authored andcommitted
Added initial version of script
1 parent e11dfdb commit d3509fb

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

scripts/update-version.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { argv, stdout } from "node:process";
2+
import { writeFileSync } from "node:fs";
3+
4+
if (argv.length !== 3) {
5+
throw new Error("expected one command line argument", {
6+
cause: argv.slice(2),
7+
});
8+
}
9+
10+
/** @type {{ isDraft: boolean; tagName: string }[]} */
11+
const arrayWithLastRelease = JSON.parse(argv[2]);
12+
13+
if (!Array.isArray(arrayWithLastRelease) || arrayWithLastRelease.length !== 1) {
14+
throw new Error("expected an array with one element", {
15+
cause: arrayWithLastRelease,
16+
});
17+
}
18+
19+
const lastRelease = arrayWithLastRelease[0];
20+
const { isDraft, tagName } = lastRelease;
21+
22+
if (
23+
Object.keys(lastRelease).length !== 2 ||
24+
typeof isDraft !== "boolean" ||
25+
typeof tagName !== "string"
26+
) {
27+
throw new Error(
28+
'expected an object with keys "isDraft" as boolean and "tagName" as string',
29+
{ cause: lastRelease },
30+
);
31+
}
32+
33+
if (!isDraft) {
34+
throw new Error(
35+
"expected a draft release to be present as the first element in the releases list",
36+
);
37+
}
38+
39+
// TODO: tagName might be prefixed with a "v" or god knows what else
40+
41+
const packageVersionFileContents = `export const PACKAGE_VERSION = "${tagName.replace('"', '\\"')}";\n`;
42+
43+
const packageVersionFilePath = new URL(
44+
"../src/package-version.ts",
45+
import.meta.url,
46+
);
47+
48+
writeFileSync(packageVersionFilePath, packageVersionFileContents);
49+
50+
stdout.write(tagName);
51+
52+
// TODO: check https://docs.npmjs.com/cli/v10/commands/npm-version#sign-git-tag
53+
// TODO: Call npm version for the output of this here script https://docs.npmjs.com/cli/v10/commands/npm-version
54+
// `npm version --commit-hooks false`;

0 commit comments

Comments
 (0)