]> git.immae.eu Git - github/fretlink/node-dhall-json-bin.git/blame - preinstall.js
Download `dhall-json` from `dhall-lang/dhall-haskell` releases
[github/fretlink/node-dhall-json-bin.git] / preinstall.js
CommitLineData
a4e6dec5
CS
1"use strict";
2
3const { https } = require("follow-redirects");
4const tar = require("tar");
5const unbz2 = require("unbzip2-stream");
6
7const pkg = require("./package.json");
8
9const trim = str => str && String(str).trim();
10
11const dhallVersion = trim(pkg["dhall-version"] || process.env.DHALL_VERSION);
12if (!dhallVersion) throw new Error("Missing DHALL_VERSION environment variable.");
13
14const dhallJsonVersion = trim(pkg["dhall-json-version"] || process.env.DHALL_JSON_VERSION);
15if (!dhallJsonVersion) throw new Error("Missing DHALL_JSON_VERSION environment variable.");
16
17const release = `https://github.com/dhall-lang/dhall-haskell/releases/download/${dhallVersion}/dhall-json-${dhallJsonVersion}`;
18
19const url = `${release}-x86_64-linux.tar.bz2`;
20https.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});