-
Notifications
You must be signed in to change notification settings - Fork 293
/
helpers.js
61 lines (58 loc) · 1.48 KB
/
helpers.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
const path = require('path');
const fs = require('fs');
/**
* Return options for iohook from package.json
* @return {Object}
*/
function optionsFromPackage(attempts) {
attempts = attempts || 2;
if (attempts > 5) {
console.log("Can't resolve main package.json file");
return {
targets: [],
platforms: [process.platform],
arches: [process.arch],
};
}
let mainPath = Array(attempts).join('../');
try {
const content = fs.readFileSync(
path.join(__dirname, mainPath, 'package.json'),
'utf-8'
);
const packageJson = JSON.parse(content);
const opts = packageJson.iohook || {};
if (!opts.targets) {
opts.targets = [];
}
if (!opts.platforms) opts.platforms = [process.platform];
if (!opts.arches) opts.arches = [process.arch];
return opts;
} catch (e) {
return optionsFromPackage(attempts + 1);
}
}
function printManualBuildParams() {
const runtime = process.versions['electron'] ? 'electron' : 'node';
const essential =
runtime +
'-v' +
process.versions.modules +
'-' +
process.platform +
'-' +
process.arch;
const modulePath = path.join(
__dirname,
'builds',
essential,
'build',
'Release',
'iohook.node'
);
console.info(
`Runtime: ${runtime} ABI: ${process.versions.modules} Platform: ${process.platform} ARCH: ${process.arch}`
);
console.info('The path is:', modulePath);
}
module.exports = { optionsFromPackage, printManualBuildParams };