forked from wilix-team/iohook
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.js
37 lines (35 loc) · 938 Bytes
/
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
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);
}
}
module.exports = { optionsFromPackage };