-
Notifications
You must be signed in to change notification settings - Fork 5
/
postinstall.js
57 lines (45 loc) · 1.23 KB
/
postinstall.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
50
51
52
53
54
55
56
57
/**
* Post Install Script
*
* Handles running npm-install on any machine dependencies in api/machines
*/
// Module dependencies
var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');
(function() {
var srcPath = path.resolve(__dirname, 'api/machines');
// Check if the srcPath exists
try {
fs.lstatSync(srcPath);
}
// If the directory doesn't exist then gracefully exit
catch(e) {
process.exit(0);
}
var deps = fs.readdirSync(srcPath).filter(function(file) {
return fs.statSync(path.join(srcPath, file)).isDirectory();
});
// Install a machine's dependencies
function install() {
var depPath = deps.pop();
var childProcess = spawn('npm', ['update'], {
cwd: path.resolve(srcPath, depPath)
});
childProcess.stdout.pipe(process.stdout);
childProcess.on('close', function(code) {
if (code) {
console.log('!EXITING DUE TO NPM INSTALL ERRORS!');
console.log('Please try running `npm install` again.');
process.exit(1);
}
if (!deps.length) {
process.exit(0);
}
// Recursively install the other dependencies
install();
});
}
// Kick on the install process
install();
})();