/
releaseDoc.js
31 lines (28 loc) · 1020 Bytes
/
releaseDoc.js
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
const insertLog = () => {
const fs = require("fs");
const log = fs.readFileSync("CHANGELOG.md", { encoding: "utf-8" });
const newLog =
"---\ntitle: 更新日志\nicon: update\n---\n\n" +
log.replace("# Changelog", "");
fs.writeFileSync("docs/ref/changelog.md", newLog, { encoding: "utf-8" });
let version = fs.readFileSync("doc-version", { encoding: "utf-8" });
version = version.split("\n")[0].trim();
const arr = version.split(".");
const sub = arr.pop();
arr.push(String(parseInt(sub) + 1));
const newVersion = arr.join(".");
fs.writeFileSync("doc-version", newVersion, { encoding: "utf-8" });
// 添加并应用
const { execSync } = require("child_process");
execSync(
`git add . && git commit -m 'docs: 更新文档' && git tag doc-${newVersion} && git push --follow-tags origin master && git push --tags`,
(err, stdout, stderr) => {
if (err) {
console.log(err);
return;
}
console.log(`stdout: ${stdout}`);
}
);
};
insertLog();