-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathinstall.js
More file actions
35 lines (28 loc) · 1.18 KB
/
install.js
File metadata and controls
35 lines (28 loc) · 1.18 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
/**
* [npm install script]
* Purpose is to automatically detect Node process architecture and run the
* corresponding script to build the library to target the appropriate architecture.
* Defaults to `node-gyp rebuild` if unable to detect the architecture.
*/
/* eslint-disable no-console */
const { spawn } = require('child_process');
function run(script) {
console.log(`Node architecture is ${process.arch}: running "${script}"`);
const program = script.split(' ')[0];
const args = script.split(' ').slice(1);
// inherit stdio to print colour (helpful for warnings/errors readability)
const child = spawn(program, args, { stdio: 'inherit', shell:true });
child.on('close', code => console.log(`Script "${script}" exited with ${code}`));
}
const buildScripts = {
x64: 'run build64',
ia32: 'run build32',
};
if (Object.prototype.hasOwnProperty.call(buildScripts, process.arch)) {
// on Windows, npm is actually `npm.cmd`
const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
run(`${npm} ${buildScripts[process.arch]}`);
} else {
console.log('Unfamiliar architecture detected, this library is probably not compatible with your OS.');
run('node-gyp rebuild');
}