1 | const path = require('path');
|
2 | const fs = require('fs');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | function optionsFromPackage(attempts) {
|
9 | attempts = attempts || 2;
|
10 | if (attempts > 5) {
|
11 | console.log("Can't resolve main package.json file");
|
12 | return {
|
13 | targets: [],
|
14 | platforms: [process.platform],
|
15 | arches: [process.arch],
|
16 | };
|
17 | }
|
18 | let mainPath = Array(attempts).join('../');
|
19 | try {
|
20 | const content = fs.readFileSync(
|
21 | path.join(__dirname, mainPath, 'package.json'),
|
22 | 'utf-8'
|
23 | );
|
24 | const packageJson = JSON.parse(content);
|
25 | const opts = packageJson.iohook || {};
|
26 | if (!opts.targets) {
|
27 | opts.targets = [];
|
28 | }
|
29 | if (!opts.platforms) opts.platforms = [process.platform];
|
30 | if (!opts.arches) opts.arches = [process.arch];
|
31 | return opts;
|
32 | } catch (e) {
|
33 | return optionsFromPackage(attempts + 1);
|
34 | }
|
35 | }
|
36 |
|
37 | function printManualBuildParams() {
|
38 | const runtime = process.versions['electron'] ? 'electron' : 'node';
|
39 | const essential =
|
40 | runtime +
|
41 | '-v' +
|
42 | process.versions.modules +
|
43 | '-' +
|
44 | process.platform +
|
45 | '-' +
|
46 | process.arch;
|
47 | const modulePath = path.join(
|
48 | __dirname,
|
49 | 'builds',
|
50 | essential,
|
51 | 'build',
|
52 | 'Release',
|
53 | 'iohook.node'
|
54 | );
|
55 | console.info(
|
56 | `Runtime: ${runtime} ABI: ${process.versions.modules} Platform: ${process.platform} ARCH: ${process.arch}`
|
57 | );
|
58 | console.info('The path is:', modulePath);
|
59 | }
|
60 |
|
61 | module.exports = { optionsFromPackage, printManualBuildParams };
|