Skip to content

Commit 94732ed

Browse files
committed
fix: move build.json creation to separate script with minor fixes
1 parent 0f59070 commit 94732ed

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test": "echo \"Error: no test specified\" && exit 1",
1111
"dev": "vuepress dev docs",
1212
"build": "vuepress build docs",
13+
"postbuild": "node src/scripts/logBuild.js",
1314
"setup": "node src/scripts/setup.js",
1415
"cli": "node src/scripts/cli.js",
1516
"release": "semantic-release",

src/scripts/logBuild.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { BRANCH } = process.env;
2+
const { writeFileSync } = require("fs");
3+
const { join } = require("path");
4+
const { execSync } = require("child_process");
5+
6+
const configPath = join(process.cwd(), "src/config/config.js");
7+
const config = require(configPath);
8+
9+
const branch = BRANCH ? BRANCH : execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).replace("\n", "");
10+
const commitId = execSync("git rev-parse HEAD", { encoding: "utf8" }).replace("\n", "");
11+
const commitUrl = "https://github.com/asterics/WebACS/commit/" + commitId;
12+
const date = Date();
13+
14+
const buildInfo = JSON.stringify({ date, branch, commitId, commitUrl }, null, 4);
15+
console.log("Creating build information:");
16+
console.log(buildInfo);
17+
writeFileSync(join(process.cwd(), config.get("destination"), "build.json"), buildInfo, "utf8");

src/scripts/semantic-release/prepare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { lstatSync, readdirSync, symlinkSync } = require("fs");
22

3-
let version = process.argv[2];
3+
const version = process.argv[2];
44

55
/* Search `docs.zip` in root folder */
66
const release = readdirSync(process.cwd())

src/scripts/setup.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const { writeFileSync } = require("fs");
21
const { join } = require("path");
3-
const { execSync } = require("child_process");
42

53
const configPath = join(process.cwd(), "src/config/config.js");
64
const indexPath = join(process.cwd(), "src/config/index.json");
@@ -30,9 +28,6 @@ config.get("versions").forEach(version => {
3028
/* Merge results */
3129
merge(latest);
3230

33-
/* Create and save build statistics */
34-
logBuildInfo();
35-
3631
//------------------------------------------------------------------------------------------
3732
//------------------------------------------------------------------------------------------
3833
function init() {
@@ -91,14 +86,3 @@ function merge(latest) {
9186
shell.mv(source, destination);
9287
});
9388
}
94-
95-
function logBuildInfo() {
96-
let branch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).replace("\n", "");
97-
let commitId = execSync("git rev-parse HEAD", { encoding: "utf8" }).replace("\n", "");
98-
let commitUrl = "https://github.com/asterics/asterics-docs/commit/" + commitId;
99-
let date = Date();
100-
101-
let buildInfo = { date, branch, commitId, commitUrl };
102-
103-
writeFileSync(join(process.cwd(), config.get("destination"), "build.json"), JSON.stringify(buildInfo, null, 4), "utf8");
104-
}

0 commit comments

Comments
 (0)