Skip to content

Commit

Permalink
fix: move build.json creation to separate script with minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sabicalija committed Mar 26, 2019
1 parent 0f59070 commit 94732ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "vuepress dev docs",
"build": "vuepress build docs",
"postbuild": "node src/scripts/logBuild.js",
"setup": "node src/scripts/setup.js",
"cli": "node src/scripts/cli.js",
"release": "semantic-release",
Expand Down
17 changes: 17 additions & 0 deletions src/scripts/logBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { BRANCH } = process.env;
const { writeFileSync } = require("fs");
const { join } = require("path");
const { execSync } = require("child_process");

const configPath = join(process.cwd(), "src/config/config.js");
const config = require(configPath);

const branch = BRANCH ? BRANCH : execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).replace("\n", "");
const commitId = execSync("git rev-parse HEAD", { encoding: "utf8" }).replace("\n", "");
const commitUrl = "/~https://github.com/asterics/WebACS/commit/" + commitId;
const date = Date();

const buildInfo = JSON.stringify({ date, branch, commitId, commitUrl }, null, 4);
console.log("Creating build information:");
console.log(buildInfo);
writeFileSync(join(process.cwd(), config.get("destination"), "build.json"), buildInfo, "utf8");
2 changes: 1 addition & 1 deletion src/scripts/semantic-release/prepare.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { lstatSync, readdirSync, symlinkSync } = require("fs");

let version = process.argv[2];
const version = process.argv[2];

/* Search `docs.zip` in root folder */
const release = readdirSync(process.cwd())
Expand Down
16 changes: 0 additions & 16 deletions src/scripts/setup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const { writeFileSync } = require("fs");
const { join } = require("path");
const { execSync } = require("child_process");

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

/* Create and save build statistics */
logBuildInfo();

//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------
function init() {
Expand Down Expand Up @@ -91,14 +86,3 @@ function merge(latest) {
shell.mv(source, destination);
});
}

function logBuildInfo() {
let branch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).replace("\n", "");
let commitId = execSync("git rev-parse HEAD", { encoding: "utf8" }).replace("\n", "");
let commitUrl = "/~https://github.com/asterics/asterics-docs/commit/" + commitId;
let date = Date();

let buildInfo = { date, branch, commitId, commitUrl };

writeFileSync(join(process.cwd(), config.get("destination"), "build.json"), JSON.stringify(buildInfo, null, 4), "utf8");
}

0 comments on commit 94732ed

Please sign in to comment.