From 16cea54a3145fb83fca64433bce602cf386917e7 Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Tue, 6 Apr 2021 14:09:20 +1000 Subject: [PATCH] Move buildnative to gyp --- nodejs/binding.gyp | 12 ++++++++++++ nodejs/package.json.gen.js | 3 +-- nodejs/postinstall.js | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/nodejs/binding.gyp b/nodejs/binding.gyp index 9539a27..a07f2ed 100644 --- a/nodejs/binding.gyp +++ b/nodejs/binding.gyp @@ -8,6 +8,18 @@ "include_dirs": [ "native/target/release/", ], + "actions": [ + { + "action_name": "build minify-html-ffi static library", + "inputs": ["native/src/lib.rs"], + "outputs": [ + "native/target/release/libminify_html_ffi.a", + "native/target/release/minify_html_ffi.h", + "native/target/release/minify_html_ffi.lib", + ], + "action": ["node", "./buildnative.js"], + } + ], "conditions": [ ["OS=='mac'", { "libraries": [ diff --git a/nodejs/package.json.gen.js b/nodejs/package.json.gen.js index 1075124..a4f28ca 100644 --- a/nodejs/package.json.gen.js +++ b/nodejs/package.json.gen.js @@ -6,8 +6,7 @@ const common = { types: "index.d.ts", files: ["postinstall.js", "index.d.ts"], scripts: { - build: - "node buildnative.js && node-gyp build && shx mv build/Release/index.node index.node", + build: "node-gyp build && shx mv build/Release/index.node index.node", clean: "cd native && cargo clean && cd .. && node-gyp clean && node-gyp configure && shx rm -f index.node", postinstall: "node postinstall.js", diff --git a/nodejs/postinstall.js b/nodejs/postinstall.js index 74c4e9b..4f87dec 100644 --- a/nodejs/postinstall.js +++ b/nodejs/postinstall.js @@ -36,9 +36,9 @@ const downloadNativeBinary = async () => { let binary; try { binary = await fetch( - `https://wilsonl.in/minify-html/bin/nodejs/${ - pkg.version - }/${pkg.name.split("/")[1]}/${binaryName}.node.gz` + `https://wilsonl.in/minify-html/bin/nodejs/${pkg.version}/${ + pkg.name.split("/")[1] + }/${binaryName}.node.gz` ); } catch (e) { if (e instanceof StatusError && attempt < MAX_DOWNLOAD_ATTEMPTS) {