forked from CloudCannon/pagefind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_version.cjs
44 lines (36 loc) · 1.11 KB
/
set_version.cjs
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
const fs = require("fs");
const path = require("path");
const changelogFile = path.join(__dirname, "../CHANGELOG.md");
const docsNavFile = path.join(__dirname, "../docs/data/nav.yml");
const err = (m) => {
console.error(m);
process.exit(1);
};
if (!fs.existsSync(changelogFile))
err(`Script expected a file at ${changelogFile}`);
let contents = fs.readFileSync(changelogFile, { encoding: "utf-8" });
let version = process.env.HUGO_PAGEFIND_DOCS_VERSION || "",
lines = contents.split(/\n/g);
let it = lines.entries();
if (!version) {
while (!(entry = it.next()).done) {
let [, line] = entry.value;
// Read until we reach the section for the latest version.
if (/^\s*##\s+v/i.test(line)) {
version = line.match(/^\s*##\s+(v\S+)/)[1];
if (version) {
break;
}
}
}
}
if (!version) {
err("No version found in changelog");
}
let docsNavContents = fs.readFileSync(docsNavFile, { encoding: "utf-8" });
docsNavContents = docsNavContents.replace(
/\blink_label:.*Local.*$/gim,
`link_label: "${version}"`
);
fs.writeFileSync(docsNavFile, docsNavContents);
console.log(version);