generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
_changelog.mjs
30 lines (25 loc) · 989 Bytes
/
_changelog.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
import { readFileSync, writeFile } from "fs";
import { Command } from "commander";
const program = new Command();
program.option("-b, --beta", "Pre-release version");
program.parse();
const opt = program.opts();
/**
* Remove text from the file
* @param {string} path
*/
function removeText(path) {
const toRemove = [
"# Changelog",
"All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.",
];
let changelog = readFileSync(path, "utf8");
for (const remove of toRemove) changelog = changelog.replace(remove, "").trim();
changelog = changelog.replaceAll(/[\n\r]{3,}/gm, "\n\n").trim();
changelog = changelog.replaceAll(/## (.*)[\n\r]{2}### /gm, "## $1\n### ").trim();
writeFile(path, changelog.trim(), "utf8", (err) => {
if (err) return console.error(err);
});
}
if (!opt.beta) removeText("CHANGELOG.md");
else removeText("CHANGELOG-beta.md");