-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-branch.js
49 lines (45 loc) · 1.04 KB
/
build-branch.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
const Git = require("nodegit");
const webpack = require("webpack");
const wpConfig = require('./webpack.prod.config');
const path = require('path');
Git.Repository.open(__dirname)
.then((repo) => {
return repo.getCurrentBranch();
})
.then((branch) => {
console.log('current branch is',branch.shorthand());
return compile({
destPath: branch.shorthand()
});
})
.catch((error) => {
console.log(error, error.message);
process.exit(1);
});
function compile({destPath}) {
return new Promise((resolve, reject) => {
wpConfig.output.path = path.join(
wpConfig.output.path, destPath
);
const compiler = webpack(wpConfig);
compiler.run((err, stats) => {
if (err || stats.hasErrors()) {
reject(
err ||
new Error(
'Stats error\n\n' +
stats.toString({
colors: true,
assets: false,
hash: false
})
)
);
}
console.log(stats.toString({
colors: true
}));
resolve();
})
})
}