forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprepareForBuild.js
More file actions
62 lines (56 loc) · 1.53 KB
/
prepareForBuild.js
File metadata and controls
62 lines (56 loc) · 1.53 KB
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
var Promise = require("nodegit-promise");
var cp = require("child_process");
var path = require("path");
var local = path.join.bind(path, __dirname);
var check = require(local("checkPrepared")).checkGenerated;
var retrieve = require(local("retrieveExternalDependencies"));
var generate = require(local("../generate"));
module.exports = function prepareForBuild() {
return new Promise(function(resolve, reject) {
cp.exec("npm install --ignore-scripts", function(err, stdout, stderr) {
if (err) {
console.error(stderr);
reject(err, stderr);
}
else {
resolve();
console.info(stdout);
}
});
}).then(function() {
return Promise.all([
retrieve(),
doGenerate()
]);
});
};
function doGenerate() {
console.info("[nodegit] Detecting generated code.");
return check().then(function(allThere) {
if (allThere) {
console.info("[nodegit] Generated code is intact.");
return Promise.resolve();
}
else {
console.info("[nodegit] Generated code is missing or incomplete, " +
"regenerating now.");
return new Promise(function(resolve, reject) {
try {
generate();
console.info("[nodegit] Code regenerated.");
resolve();
}
catch (e) {
console.info("[nodegit] Error generating code.");
console.info(e);
//console.info(stderr);
reject(e);
}
});
}
});
}
// Called on the command line
if (require.main === module) {
module.exports();
}