Skip to content

Commit

Permalink
Merge pull request #316 from wilix-team/enhancement-targets
Browse files Browse the repository at this point in the history
Enhancement for package.json iohook configuration
  • Loading branch information
WilixLead authored Apr 19, 2021
2 parents aab2e4c + 136ec23 commit 01ec9eb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function initBuild() {

return uploadFiles(files)
});

cpGyp();
}

Expand Down Expand Up @@ -145,7 +145,7 @@ function build(runtime, version, abi) {
}
}

console.log('Compiling iohook for ' + runtime + ' v' + version + '>>>>');
console.log('Building iohook for ' + runtime + ' v' + version + '>>>>');
if (process.platform === 'win32') {
if (version.split('.')[0] >= 4) {
process.env.msvs_toolset = 15
Expand Down
1 change: 1 addition & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ iohook currently provides prebuilt versions for the following runtimes:
- 9.X.X (ABI 80)
- 10.X.X (ABI 82)
- 11.X.X (ABI 85)
- 12.X.X (ABI 87)

- Node.js:
- 8.9.X (ABI 57)
Expand Down
20 changes: 20 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ Checkout your ABI for [node.js](https://nodejs.org/en/download/releases/) or [el
}
```

Or you can specify targets as objects:

```json
"iohook": {
"targets": [
{
"target": "node",
"abi": "72",
"platform": "darwin",
"arch": "x64"
},
{
"target": "electron",
"abi": "85",
"platform": "win32",
"arch": "ia32"
},
],
```

::: tip
if you use a two-package.json structure, add this to application package.json.
:::
Expand Down
2 changes: 1 addition & 1 deletion examples/electron-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "Aloyan Dmitry",
"license": "MIT",
"dependencies": {
"electron": "^11.0.0"
"electron": ">=11.1.0"
}
}
2 changes: 1 addition & 1 deletion examples/electron-renderer-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"start": "electron ."
},
"devDependencies": {
"electron": "^11.0.0"
"electron": ">=11.1.0"
}
}
16 changes: 13 additions & 3 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function install(runtime, abi, platform, arch, cb) {
onerror(error);
} else {
console.error('Prebuild for current platform (' + currentPlatform + ') not found!');
console.error('Try to compile for your platform:');
console.error('Try to build for your platform manually:');
console.error('# cd node_modules/iohook;');
console.error('# npm run build');
console.error('');
Expand Down Expand Up @@ -96,10 +96,10 @@ function install(runtime, abi, platform, arch, cb) {
}

const options = optionsFromPackage();

if (process.env.npm_config_targets) {
options.targets = options.targets.concat(process.env.npm_config_targets.split(','));
}
options.targets = options.targets.map(targetStr => targetStr.split('-'));
if (process.env.npm_config_targets === 'all') {
options.targets = supportedTargets.map(arr => [arr[0], arr[2]]);
options.platforms = ['win32', 'darwin', 'linux'];
Expand All @@ -115,7 +115,17 @@ if (process.env.npm_config_arches) {
// Choice prebuilds for install
if (options.targets.length > 0) {
let chain = Promise.resolve();
options.targets.forEach(function(parts) {
options.targets.forEach(function(target) {
if (typeof target === 'object') {
chain = chain.then(function() {
return new Promise(function(resolve) {
console.log(target.runtime, target.abi, target.platform, target.arch);
install(target.runtime, target.abi, target.platform, target.arch, resolve)
})
});
return;
}
let parts = target.split('-');
let runtime = parts[0];
let abi = parts[1];
options.platforms.forEach(function(platform) {
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01ec9eb

Please sign in to comment.