forked from maidsafe-archive/safe_launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebuild_native.js
46 lines (39 loc) · 1.33 KB
/
rebuild_native.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
import os from 'os';
import childProcess from 'child_process';
import path from 'path';
import electron from 'electron-prebuilt';
import * as rebuild from 'electron-rebuild';
const pathToElectronNativeModules = path.join(__dirname, '/node_modules');
const electronVersion = require('electron-prebuilt/package.json').version;
const rebuildNativeModules = () => {
rebuild.shouldRebuildNativeModules(electron)
.then((shouldBuild) => {
if (!shouldBuild) {
return true;
}
return rebuild.installNodeHeaders(electronVersion)
.then(() => rebuild.rebuildNativeModules(electronVersion, pathToElectronNativeModules));
})
.then(() => console.warn('Rebuilding complete'))
.catch((err) => {
console.error('Rebuilding error!');
console.error(err);
});
};
const rebuildForWindows = () => {
const mods = ['ffi', 'ref'];
let mod = null;
for (mod of mods) {
console.warn('Rebuilding ', mod);
childProcess.execSync(`node-gyp rebuild --target=${electronVersion} --arch=${os.arch()} --dist-url=https://atom.io/download/atom-shell`, { cwd: `node_modules/${mod}` });
}
console.warn('Rebuilding complete.');
};
const run = () => {
console.warn('Rebuilding native modules');
if (os.platform() === 'win32') {
return rebuildForWindows();
}
return rebuildNativeModules();
};
run();