forked from jdorner/node-sapnwrfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreinstall.js
43 lines (38 loc) · 1.17 KB
/
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
40
41
42
43
var os = require('os');
var child_process = require('child_process');
var red = '\u001b[31m',
green = '\u001b[32m',
reset = '\u001b[0m';
var nodeGyp = function () {
switch (os.platform()) {
case 'win32':
return 'node-gyp.cmd';
case 'linux':
case 'darwin':
default:
return 'node-gyp';
}
};
var rebuild = function () {
if (os.platform() === 'darwin') {
return console.log('NOT SUPPORTED UNDER DARWIN.');
};
try {
var majMinVersion = process.versions.node.match(/^[0-9]+.[0-9]+/)[0] || '';
var bindings = require('bindings')({ bindings: 'sapnwrfc', version: majMinVersion });
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.stdio = [0, 1, 2];
opts.env = process.env;
child_process.spawn(nodeGyp(), ['rebuild'], opts);
}
};
var opts = {};
opts.stdio = [0, 1, 2];
var cp = child_process.spawn(nodeGyp(), ['clean'], opts);
cp.on('exit', rebuild);