diff options
author | Cyril Sobierajewicz <cyril.sobierajewicz@fretlink.com> | 2019-05-17 13:39:14 +0200 |
---|---|---|
committer | Cyril Sobierajewicz <cyril.sobierajewicz@fretlink.com> | 2019-05-20 13:51:27 +0200 |
commit | a4e6dec5fcffa5d51a96722a07668bab02336d5f (patch) | |
tree | 07c8178054cab431d6347c21ca7298248c45845a /preinstall.js | |
parent | ad22b841da176ee40686f04cc70ceaca51da1925 (diff) | |
download | node-dhall-json-bin-a4e6dec5fcffa5d51a96722a07668bab02336d5f.tar.gz node-dhall-json-bin-a4e6dec5fcffa5d51a96722a07668bab02336d5f.tar.zst node-dhall-json-bin-a4e6dec5fcffa5d51a96722a07668bab02336d5f.zip |
Download `dhall-json` from `dhall-lang/dhall-haskell` releases
Diffstat (limited to 'preinstall.js')
-rw-r--r-- | preinstall.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/preinstall.js b/preinstall.js new file mode 100644 index 0000000..1b859fc --- /dev/null +++ b/preinstall.js | |||
@@ -0,0 +1,23 @@ | |||
1 | "use strict"; | ||
2 | |||
3 | const { https } = require("follow-redirects"); | ||
4 | const tar = require("tar"); | ||
5 | const unbz2 = require("unbzip2-stream"); | ||
6 | |||
7 | const pkg = require("./package.json"); | ||
8 | |||
9 | const trim = str => str && String(str).trim(); | ||
10 | |||
11 | const dhallVersion = trim(pkg["dhall-version"] || process.env.DHALL_VERSION); | ||
12 | if (!dhallVersion) throw new Error("Missing DHALL_VERSION environment variable."); | ||
13 | |||
14 | const dhallJsonVersion = trim(pkg["dhall-json-version"] || process.env.DHALL_JSON_VERSION); | ||
15 | if (!dhallJsonVersion) throw new Error("Missing DHALL_JSON_VERSION environment variable."); | ||
16 | |||
17 | const release = `https://github.com/dhall-lang/dhall-haskell/releases/download/${dhallVersion}/dhall-json-${dhallJsonVersion}`; | ||
18 | |||
19 | const url = `${release}-x86_64-linux.tar.bz2`; | ||
20 | https.get(url, res => { | ||
21 | if (res.statusCode >= 400) throw new Error(`Error fetching ${url}: ${res.statusMessage}`); | ||
22 | res.pipe(unbz2()).pipe(tar.x({ C: __dirname })); | ||
23 | }); | ||