Skip to content

Commit 16470ad

Browse files
committed
Add prebuildify and prebuild script
1 parent a9b4091 commit 16470ad

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ coverage
2121

2222
# Compiled binary addons (http://nodejs.org/api/addons.html)
2323
build/Release
24+
prebuilds
2425

2526
# Dependency directory
2627
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git

js/scripts/prebuild.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const {spawnSync} = require('child_process');
2+
3+
main().catch(e => {
4+
throw e;
5+
});
6+
7+
async function main() {
8+
console.log('Building distribution binary...'); // eslint-disable-line no-console
9+
10+
const prebuildArch = getNodearch(process.env.ARCH);
11+
12+
// napi is forward compatible so we only build for two targets (Node and Electron)
13+
let prebuildScript = `prebuildify --napi --arch=${prebuildArch} -t 12.0.0 -t [email protected] --strip`;
14+
15+
if (process.platform == 'linux') {
16+
prebuildScript = `${prebuildScript} --tag-libc`;
17+
}
18+
19+
spawnSync(prebuildScript, {
20+
shell: true,
21+
stdio: 'inherit',
22+
encoding: 'utf8',
23+
});
24+
}
25+
26+
/**
27+
* @param {string | undefined} arch the given architecture
28+
* @returns {string} the Node architecture to build for
29+
*/
30+
function getNodearch(arch) {
31+
if (!arch) {
32+
return process.arch;
33+
}
34+
if (arch === 'x86') {
35+
return 'ia32';
36+
} else {
37+
return arch;
38+
}
39+
}

js/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { promises: fs } = require('fs');
22
const path = require('path');
33

4-
const NSFW = require('../../build/Release/nsfw.node');
4+
const NSFW = require('../../binding');
55

66
function NSFWFilePoller(watchPath, eventCallback, debounceMS) {
77
const { CREATED, DELETED, MODIFIED } = nsfw.actions;

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"install": "node-gyp-build",
88
"lint": "eslint js/src js/spec",
9-
"test": "yarn lint && node js/scripts/test.js"
9+
"test": "yarn lint && node js/scripts/test.js",
10+
"prebuild": "node ./js/scripts/prebuild.js"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -26,7 +27,8 @@
2627
"js/src",
2728
"src",
2829
"includes",
29-
"binding.gyp"
30+
"binding.gyp",
31+
"prebuilds"
3032
],
3133
"homepage": "https://github.com/axosoft/node-simple-file-watcher",
3234
"dependencies": {
@@ -37,7 +39,8 @@
3739
"eslint": "^6.8.0",
3840
"executive": "^1.6.3",
3941
"fs-extra": "^7.0.0",
40-
"mocha": "^7.1.1"
42+
"mocha": "^7.1.1",
43+
"prebuildify": "^4.1.2"
4144
},
4245
"keywords": [
4346
"FileWatcher",

0 commit comments

Comments
 (0)