]>
git.immae.eu Git - github/fretlink/node-dhall-json-bin.git/blob - preinstall.js
071f1590eb2c9e922dc61abf5fd0083878e88855
3 const fs
= require("fs");
4 const path
= require("path");
6 const { https
} = require("follow-redirects");
7 const tar
= require("tar");
8 const unbz2
= require("unbzip2-stream");
9 const unzipper
= require("unzipper");
11 const pkg
= require("./package.json");
12 const bindir
= path
.join(__dirname
, "bin");
14 const trim
= str
=> str
&& String(str
).trim();
16 const dhallVersion
= trim(pkg
["dhall-version"] || process
.env
.DHALL_VERSION
);
17 if (!dhallVersion
) throw new Error("Missing DHALL_VERSION environment variable.");
19 const dhallJsonVersion
= trim(pkg
["dhall-json-version"] || process
.env
.DHALL_JSON_VERSION
);
20 if (!dhallJsonVersion
) throw new Error("Missing DHALL_JSON_VERSION environment variable.");
22 const release
= `https://github.com/dhall-lang/dhall-haskell/releases/download/${dhallVersion}/dhall-json-${dhallJsonVersion}`;
24 const get = (archive
, callback
) => {
25 const url
= `${release}-${archive}`;
26 return https
.get(url
, res
=> {
27 if (res
.statusCode
>= 400) throw new Error(`Error fetching ${url}: ${res.statusMessage}`);
32 if (process
.platform
=== "win32") {
33 get("x86_64-windows.zip", res
=>
34 res
.pipe(unzipper
.Extract({ path: bindir
}))
37 get("x86_64-linux.tar.bz2", res
=>
38 res
.pipe(unbz2()).pipe(tar
.x({ C: __dirname
}).on("finish", () => {
39 fs
.readdir(bindir
, (err
, names
) => {
41 for (const name
of names
) {
42 fs
.rename(path
.join(bindir
, name
), path
.join(bindir
, name
+ ".exe"), err
=> {