Skip to content

Commit 44af381

Browse files
committed
feat(package): add version hook
1 parent 5ff34fc commit 44af381

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
message="chore(package): bump version number to v%s"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"baseline-accept": "cpx \"generated\\*\" baselines\\",
1919
"lint": "eslint --max-warnings 0 src",
2020
"test": "npm run lint && npm run build && node ./lib/test.js && node ./unittests/index.js",
21-
"changelog": "tsc && node ./lib/changelog.js"
21+
"changelog": "tsc && node ./lib/changelog.js",
22+
"version": "tsc && node ./lib/version.js"
2223
},
2324
"author": {
2425
"name": "Kagami Sascha Rosylight",

src/changelog.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { execSync } from "child_process";
22
import ts from "typescript";
3+
import { fileURLToPath } from "url";
34

45
function gitShowFile(commit: string, path: string) {
56
return execSync(`git show ${commit}:${path}`, { encoding: "utf-8" });
@@ -136,7 +137,7 @@ function writeAddedRemovedInline(added: Set<string>, removed: Set<string>) {
136137

137138
const dom = "baselines/dom.generated.d.ts";
138139

139-
async function main() {
140+
export function generate(): string {
140141
const [base = gitLatestTag(), head = "HEAD"] = process.argv.slice(2);
141142
const previous = gitShowFile(base, dom);
142143
const current = gitShowFile(head, dom);
@@ -165,11 +166,14 @@ async function main() {
165166
}
166167

167168
const output = outputs.join("\n\n");
168-
if (output.length) {
169-
console.log(output);
170-
} else {
169+
170+
if (!output.length) {
171171
throw new Error(`No change reported between ${base} and ${head}.`);
172172
}
173+
174+
return output;
173175
}
174176

175-
await main();
177+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
178+
console.log(generate());
179+
}

src/version.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { execSync } from "child_process";
2+
import { readFile, writeFile } from "fs/promises";
3+
import { generate } from "./changelog.js";
4+
5+
const output = generate();
6+
7+
const path = new URL("../CHANGELOG.md", import.meta.url);
8+
9+
const content = await readFile(path, "utf-8");
10+
11+
const { npm_package_version } = process.env;
12+
13+
await writeFile(path, `# v${npm_package_version}\n\n${output}\n\n${content}`);
14+
15+
execSync("git add CHANGELOG.md");

0 commit comments

Comments
 (0)