-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathbuild-if-not-git-repo.js
44 lines (37 loc) · 1.22 KB
/
build-if-not-git-repo.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
/* eslint-env node */
// Runs a webpack build when not installed in a git repository (i.e. when installed from GitHub in node_modules)
// Largely pulled from https://github.com/typicode/husky/blob/9d3eb31cd14d3fbdb77225d23a0c5a11f71beb2c/src/index.ts#L23
const cp = require("child_process");
const webpack = require("webpack");
const config = require("../webpack.config.js");
/**
* Logger
* @param {string} msg
* @returns {void}
*/
const l = (msg) => console.log(`replaywebpage - ${msg}`);
/**
* Git command
* @param {string[]} args
* @returns {cp.SpawnSyncReturns<Buffer>}
*/
const git = (args) => cp.spawnSync("git", args, { stdio: "inherit" });
// Ensure that we're inside a Git repository
// If git command is not found, status is null and we should return
// That's why status value needs to be checked explicitly
if (git(["rev-parse"]).status !== 0 || process.argv.includes("--force")) {
l(`git command not found, running build`);
const compiler = webpack(config.map((c) => c(process.env, process.argv)));
compiler.run((err) => {
if (err) {
console.error(err);
process.exit(1);
}
compiler.close((err) => {
if (err) {
console.error(err);
process.exit(1);
}
});
});
}