-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
64 lines (55 loc) · 1.77 KB
/
build.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
58
59
60
61
62
63
64
#!/usr/bin/env node
// Checks if we have a pre-built binary, if not attempt to build one
// Usage: node build.js
var spawn = require('child_process').spawn;
var fs = require('fs');
var path = require('path');
var arch = process.arch;
var platform = process.platform;
var v8 = /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
var force = false;
var args = process.argv.slice(2).filter(function(arg) {
if (arg.slice(0, 13) === '--target_arch') {
arch = arg.slice(14);
} else if (arg.slice(0, 7) === '--force') {
force = true;
}
return true;
});
if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {
console.error('Unsupported (?) architecture: `' + arch + '`');
process.exit(1);
}
var binPath = path.join(__dirname, 'bin');
if (!fs.existsSync(binPath)) {
fs.mkdirSync(binPath);
}
var installPath = path.join(binPath, platform + '-' + arch + '-v8-' + v8, 'pathwatcher.node');
if (force && fs.existsSync(installPath)) {
fs.unlinkSync(installPath);
}
if (!fs.existsSync(installPath)) {
var child = spawn(process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'].concat(args), { stdio: 'inherit' });
child.on('exit', function(err) {
if (err) {
if (err === 127) {
console.error('node-gyp not found! Please npm install npm -g');
} else {
console.error('Build failed');
}
return process.exit(err);
}
var targetPath = path.join(__dirname, 'build', 'Release', 'pathwatcher.node');
var installDir = path.dirname(installPath);
if (!fs.existsSync(installDir)) {
fs.mkdirSync(installDir);
}
try {
fs.statSync(targetPath);
} catch (err) {
console.error('Build succeeded but target not found');
process.exit(1);
}
fs.renameSync(targetPath, installPath);
});
}