-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiohook-prebuilt-replace.js
51 lines (41 loc) · 1.38 KB
/
iohook-prebuilt-replace.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
/* eslint-disable no-restricted-syntax */
const fse = require('fs-extra');
const path = require('path');
const rimraf = require('rimraf');
const unzipper = require('unzipper');
const { sep } = path;
const binarys = {
darwin: ['electron-v87-darwin-x64'],
win32: ['electron-v87-win32-ia32', 'electron-v87-win32-x64'],
linux: ['electron-v87-linux-x64'],
};
const sourcePath = `.${sep}iohook-prebuilts${sep}builds`;
const targetPath = `.${sep}src${sep}node_modules${sep}iohook${sep}builds`;
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// Binaries on some platforms seems to be not provided or are error-prone
// So, replace these prebuilt binary files with this.
rimraf(targetPath, (err) => {
if (err) {
throw new Error(`Error on ${__filename}`, err);
}
for (const target of binarys[process.platform]) {
const source = `${sourcePath}${sep}${target}`;
rimraf(source, () => {
const dest = `${targetPath}${sep}${target}`;
const copyPipe = fse
.createReadStream(`${source}.zip`)
.pipe(unzipper.Extract({ path: source }));
copyPipe.on('finish', async () => {
await sleep(1000);
fse.copy(source, dest, {
recursive: true,
overwrite: true,
preserveTimestamps: true,
});
});
});
}
console.log(`${sourcePath} was replaced with ${targetPath}`);
});