|
1 | | -const os = require('os'); |
2 | | -const { join } = require('path'); |
3 | | -const { execSync } = require('child_process'); |
4 | | -const { pathExistsSync, copySync, removeSync } = require('fs-extra'); |
| 1 | +const path = require('path'); |
5 | 2 | const argv = require('yargs').argv; |
| 3 | +const electronRebuild = require('electron-rebuild'); |
6 | 4 |
|
7 | | -const nativeModules = [ |
8 | | - join(__dirname, '../node_modules/node-pty'), |
9 | | - join(__dirname, '../node_modules/nsfw'), |
10 | | - join(__dirname, '../node_modules/spdlog') |
11 | | -] |
| 5 | +const electronVersion = argv.electronVersion || require('electron/package.json').version; |
12 | 6 |
|
13 | | -let commands; |
| 7 | +console.log('rebuilding native for electron version ' + electronVersion); |
| 8 | +const force = argv['force-rebuild'] === 'true'; |
| 9 | +const buildPath = path.resolve(__dirname, '..'); |
14 | 10 |
|
15 | | -const target = argv.target || 'node'; |
16 | | -const arch = argv.arch || os.arch(); |
17 | | -let version; |
18 | | - |
19 | | -if (target === 'electron') { |
20 | | - |
21 | | - version = argv.electronVersion || require('electron/package.json').version; |
22 | | - |
23 | | - console.log('rebuilding native for electron version ' + version); |
24 | | - |
25 | | - commands = [ |
26 | | - `npm_config_arch=${arch}`, |
27 | | - `npm_config_target_arch=${arch}`, |
28 | | - os.platform() === 'win32' |
29 | | - ? 'set HOME=~/.electron-gyp' |
30 | | - : 'HOME=~/.electron-gyp', |
31 | | - |
32 | | - os.platform() === 'win32' |
33 | | - ? join(__dirname, '..\\node_modules\\.bin\\electron-rebuild.cmd') |
34 | | - : join(__dirname, '../node_modules/.bin/electron-rebuild'), |
35 | | - ]; |
36 | | - |
37 | | -} else if (target === 'node') { |
38 | | - |
39 | | - console.log('rebuilding native for node version ' + process.version); |
40 | | - |
41 | | - version = process.version; |
42 | | - |
43 | | - commands = ['node-gyp', 'rebuild'] |
44 | | - |
45 | | -} |
46 | | - |
47 | | -function rebuildModule(modulePath, type, version) { |
48 | | - const info = require(join(modulePath, './package.json')); |
49 | | - console.log('rebuilding ' + info.name) |
50 | | - const cache = getBuildCacheDir(modulePath, type, version, target); |
51 | | - if (pathExistsSync(cache) && !argv['force-rebuild']) { |
52 | | - console.log('cache found for ' + info.name) |
53 | | - copySync(cache, join(modulePath, 'build')); |
54 | | - } |
55 | | - else { |
56 | | - const command = commands.join(' '); |
57 | | - console.log(command); |
58 | | - execSync(command, { |
59 | | - cwd: modulePath, |
60 | | - HOME: target === 'electron' ? '~/.electron-gyp' : undefined |
61 | | - }); |
62 | | - removeSync(cache); |
63 | | - copySync(join(modulePath, 'build'), cache); |
64 | | - } |
65 | | - |
66 | | -} |
67 | | - |
68 | | -function getBuildCacheDir(modulePath, type, version, target) { |
69 | | - const info = require(join(modulePath, './package.json')); |
70 | | - return join(require('os').tmpdir(), 'ide_build_cache', target, info.name + '-' + info.version, type + '-' + version); |
| 11 | +if (force) { |
| 12 | + console.log('Force rebuild flag enabled.'); |
71 | 13 | } |
72 | 14 |
|
73 | | - |
74 | | -nativeModules.forEach(path => { |
75 | | - rebuildModule(path, target, version); |
76 | | -}) |
| 15 | +electronRebuild.rebuild({ buildPath, electronVersion, force }) |
0 commit comments