-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
74 lines (63 loc) · 2.65 KB
/
release.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* eslint-disable global-require */
/* eslint-disable @typescript-eslint/no-var-requires */
const { spawn } = require("child_process");
const fs = require("fs");
const { cwd } = require("process");
async function go() {
function exec(cmd, args, isGetResult) {
return new Promise((resolve, reject) => {
const child = spawn(cmd, args || [("--progress", "--colors")], {
shell: true,
stdio: isGetResult ? "pipe" : "inherit",
cwd: cwd(),
});
let msg;
child.stdout?.on("data", (data) => (msg = data.toString()));
child.on("error", reject);
child.on("exit", (code) => (code === 0 ? resolve(msg) : reject(code)));
});
}
/* checking master branch */
const msg = await exec("git rev-parse --abbrev-ref HEAD", [], true);
if (!msg.includes("master")) {
throw new Error("Only master branch expected");
}
/* set date in changelog */
const monthsShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const dt = new Date();
const gotDate = `(${monthsShort[dt.getUTCMonth()]} ${dt.getUTCDate()}, ${dt.getUTCFullYear()})`;
const txt = fs
.readFileSync("./CHANGELOG.md", { encoding: "utf8" })
.replace("(___)", gotDate)
.replace("(\\_\\_\\_)", gotDate);
fs.writeFileSync("./CHANGELOG.md", txt, { encoding: "utf8" });
const ver = /## ([0-9.]+)/.exec(txt)[1];
/* update version in package.json */
const verReg = /("version": ")([0-9.]+)/;
fs.writeFileSync(
"./package.json", //
fs.readFileSync("./package.json", { encoding: "utf8" }).replace(verReg, `$1${ver}`),
{ encoding: "utf8" }
);
fs.writeFileSync(
"./package-lock.json",
fs.readFileSync("./package-lock.json", { encoding: "utf8" }).replace(verReg, `$1${ver}`),
{ encoding: "utf8" }
);
// await exec("npm version patch --commit-hooks false --git-tag-version false", []);
// await exec("npm run build"); // run build again because version is changed
await exec("npm run coverage"); // build for test + tests + publish coverage
await exec("npm run build"); // building prod version with removing comments
await exec("npm run build-demo"); // building demo
/* commit files */
// const { version } = require("./package.json");
await exec(`git config core.autocrlf false && git add . && git commit -m "Bump version to ${ver}"`, []);
await exec(`git tag v${ver}`, []);
// publish to npm
// await exec("cd ./dist && npm publish");
// push files
// await exec("git push && git push --tags", []);
console.warn("The current release is DONE. Check commit, tag and push both into Github");
console.warn("use `npm run go-publish` to publish you package");
}
go();