Skip to content

Commit bc2c865

Browse files
committed
Switch to git tags
1 parent c7b84c0 commit bc2c865

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

deploy/versionChangelog.mjs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// npm run ts-changelog @types/web 0.0.1 0.0.3
44

55
import { generateChangelogFrom } from "../lib/changelog.js";
6-
import fetch from "node-fetch";
6+
import { packages } from "./createTypesPackages.mjs";
7+
import { execSync } from "child_process";
8+
import { basename } from "path";
79

810
const [name, before, to] = process.argv.slice(2);
911
if (!name || !before || !to) {
@@ -12,26 +14,26 @@ if (!name || !before || !to) {
1214
);
1315
}
1416

15-
const go = async () => {
16-
const allFiles = `https://unpkg.com/${name}/?meta`;
17-
const npmFileReq = await fetch(allFiles);
18-
const npmDTSFiles = await npmFileReq.json();
19-
const dtsFiles = npmDTSFiles.files.filter((f) => f.path.endsWith(".d.ts"));
17+
const go = () => {
18+
// We'll need to map back from the filename in the npm package to the
19+
// generated file in baselines inside the git tag
20+
const thisPackageMeta = packages.find((p) => p.name === name);
21+
if (!thisPackageMeta)
22+
throw new Error(`Could not find ${name} in ${packages.map((p) => p.name)}`);
2023

21-
for (const file of dtsFiles) {
22-
const beforeURI = `https://unpkg.com/${name}@${before}${file.path}`;
23-
const npmBeforeFileReq = await fetch(beforeURI);
24-
const npmBeforeFileText = await npmBeforeFileReq.text();
24+
for (const file of thisPackageMeta.files) {
25+
const filename = `baselines/${basename(file.from)}`;
26+
const beforeFileText = gitShowFile(`${name}@${before}`, filename);
27+
const toFileText = gitShowFile(`${name}@${to}`, filename);
2528

26-
const toURI = `https://unpkg.com/${name}@${to}${file.path}`;
27-
const npmToFileReq = await fetch(toURI);
28-
const npmToFileText = await npmToFileReq.text();
29+
const notes = generateChangelogFrom(beforeFileText, toFileText);
2930

30-
const title = `\n## \`${file.path.slice(1)}\`\n`;
31-
const notes = generateChangelogFrom(npmBeforeFileText, npmToFileText);
32-
33-
console.log(title);
31+
console.log(`\n## \`${file.to}\`\n`);
3432
console.log(notes.trim() === "" ? "No changes" : notes);
3533
}
3634
};
35+
36+
const gitShowFile = (commitish, path) =>
37+
execSync(`git show "${commitish}":${path}`, { encoding: "utf-8" });
38+
3739
go();

0 commit comments

Comments
 (0)