forked from jdorner/node-sapnwrfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreinstall.js
39 lines (34 loc) · 1000 Bytes
/
preinstall.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
var child_process = require('child_process');
var red = '\u001b[31m',
green = '\u001b[32m',
reset = '\u001b[0m';
var nodeGyp = function() {
var os = require('os');
switch (os.platform()) {
case 'win32':
return 'node-gyp.cmd';
case 'linux':
case 'darwin':
default:
return 'node-gyp';
}
}
var rebuild = function() {
try {
var bindings = require('bindings')('sapnwrfc');
console.log(green + 'ok ' + reset + 'found precompiled module at ' + bindings.path);
} catch (e) {
console.log(e);
console.log(red + 'error ' + reset + 'a precompiled module could not be found or loaded');
// Spawn gyp
console.log(green + 'info ' + reset + 'trying to compile it...');
var opts = {};
opts.customFds = [ 0, 1, 2 ];
opts.env = process.env;
child_process.spawn(nodeGyp(), ['rebuild'], opts);
}
}
var opts = {};
opts.customFds = [ 0, 1, 2 ];
var cp = child_process.spawn(nodeGyp(), ['clean'], opts);
cp.on('exit', rebuild);