]>
git.immae.eu Git - github/fretlink/node-dhall-json-bin.git/blob - preinstall.js
3fa23826d370bbdd3021e1814e2595bf4e27f319
3 const fs
= require("fs");
4 const path
= require("path");
6 const { https
} = require("follow-redirects");
7 const semver
= require("semver");
8 const tar
= require("tar");
9 const unbz2
= require("unbzip2-stream");
10 const unzipper
= require("unzipper");
12 const pkg
= require("./package.json");
13 const bindir
= path
.join(__dirname
, "bin");
15 const trim
= str
=> str
&& String(str
).trim();
17 const dhallVersion
= trim(pkg
["dhall-version"] || process
.env
.DHALL_VERSION
);
18 if (!dhallVersion
) throw new Error("Missing DHALL_VERSION environment variable.");
20 const dhallJsonVersion
= trim(pkg
["dhall-json-version"] || process
.env
.DHALL_JSON_VERSION
);
21 if (!dhallJsonVersion
) throw new Error("Missing DHALL_JSON_VERSION environment variable.");
22 if (semver
.valid(dhallJsonVersion
) && semver
.lt(dhallJsonVersion
, "1.2.8")) {
23 throw new Error(`This release of the \`${pkg.name}
\` npm package installs \`json
-to
-dhall
\`, which isn’t provided by \`dhall
-json
@<1.2.8\`.`);
26 const release
= `https://github.com/dhall-lang/dhall-haskell/releases/download/${dhallVersion}/dhall-json-${dhallJsonVersion}`;
28 const get = (archive
, callback
) => {
29 const url
= `${release}-${archive}`;
30 return https
.get(url
, res
=> {
31 if (res
.statusCode
>= 400) throw new Error(`Error fetching ${url}: ${res.statusMessage}`);
36 if (process
.platform
=== "win32") {
37 get("x86_64-windows.zip", res
=>
38 res
.pipe(unzipper
.Extract({ path: bindir
}))
41 get("x86_64-linux.tar.bz2", res
=>
42 res
.pipe(unbz2()).pipe(tar
.x({ C: __dirname
}).on("finish", () => {
43 fs
.readdir(bindir
, (err
, names
) => {
45 for (const name
of names
) {
46 fs
.rename(path
.join(bindir
, name
), path
.join(bindir
, name
+ ".exe"), err
=> {