/
changelog-for-patch.mjs
44 lines (39 loc) · 1.02 KB
/
changelog-for-patch.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
import path from "node:path";
import minimist from "minimist";
import semver from "semver";
import {
changelogUnreleasedDirPath,
changelogUnreleasedDirs,
getEntries,
printEntries,
replaceVersions,
} from "./utils/changelog.mjs";
const { previousVersion, newVersion } = parseArgv();
const entries = changelogUnreleasedDirs.flatMap((dir) => {
const dirPath = path.join(changelogUnreleasedDirPath, dir.name);
return getEntries(dirPath);
});
console.log(
replaceVersions(
printEntries(entries).join("\n\n"),
previousVersion,
newVersion,
/** isPatch */ true
)
);
function parseArgv() {
const argv = minimist(process.argv.slice(2));
const previousVersion = argv["prev-version"];
const newVersion = argv["new-version"];
if (
!previousVersion ||
!newVersion ||
semver.compare(previousVersion, newVersion) !== -1
) {
throw new Error(
`Invalid argv, prev-version: ${previousVersion}, new-version: ${newVersion}`
);
}
return { previousVersion, newVersion };
}