Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 38 additions & 90 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,70 @@
var fs = require("fs");
var axios = require("axios");
var tar = require("tar");
var zlib = require("zlib");
var unzip = require("unzip-stream");
var path = require("path");


var packageInfo = require(path.join(process.cwd(), "package.json"));
var version = packageInfo.version;

var binName = process.argv[2];
var os = process.argv[3] || process.platform;
var arch = process.argv[4] || process.arch;
var root = `https://github.com/SAP/${binName}/releases/download/v${version}/${binName}_${version}_`;


var requested = os + "-" + arch;
var current = process.platform + "-" + process.arch;
const fs = require("node:fs");
const tar = require("tar");
const zlib = require("node:zlib");
const path = require("node:path");
const { Readable } = require("node:stream");

const packageInfo = require(path.join(process.cwd(), "package.json"));
const version = packageInfo.version;

const binName = process.argv[2];
const os = process.argv[3] || process.platform;
const arch = process.argv[4] || process.arch;
const root = `https://github.com/SAP/${binName}/releases/download/v${version}/${binName}_${version}_`;

const requested = os + "-" + arch;
const current = process.platform + "-" + process.arch;
if (requested !== current ) {
console.error("WARNING: Installing binaries for the requested platform (" + requested + ") instead of for the actual platform (" + current + ").")
}

var unpackedBinPath = path.join(process.cwd(), "unpacked_bin");
var config = {
const unpackedBinPath = path.join(process.cwd(), "unpacked_bin");
const config = {
dirname: __dirname,
binaries: [
'mbt'
'mbt'
],
urls: {
'darwin-arm64': root + 'Darwin_arm64.tar.gz',
'darwin-x64': root + 'Darwin_amd64.tar.gz',
'linux-x64': root + 'Linux_amd64.tar.gz',
'linux-arm64': root + 'Linux_arm64.tar.gz',
'win32-x64': root + 'Windows_amd64.tar.gz'
'darwin-arm64': root + 'Darwin_arm64.tar.gz',
'darwin-x64': root + 'Darwin_amd64.tar.gz',
'linux-x64': root + 'Linux_amd64.tar.gz',
'linux-arm64': root + 'Linux_arm64.tar.gz',
'win32-x64': root + 'Windows_amd64.tar.gz'
}
};
if (!fs.existsSync("bin")) {
fs.mkdirSync("bin");
}

var binExt = "";
let binExt = "";
if (os == "win32") {
binExt = ".exe";
}

var buildId = os + "-" + arch;
var url = config.urls[buildId];
const buildId = os + "-" + arch;
const url = config.urls[buildId];
if (!url) {
throw new Error("No binaries are available for your platform: " + buildId);
}

function binstall(url, path, options) {
if (url.endsWith(".zip")) {
return unzipUrl(url, path, options);
} else {
return untgz(url, path, options);
}
return untgz(url, path, options);
}

function untgz(url, path, options) {
options = options || {};

var verbose = options.verbose;
var verify = options.verify;
const verbose = options.verbose;
const verify = options.verify;

return new Promise(function (resolve, reject) {
var untar = tar
const untar = tar
.x({ cwd: path })
.on("error", function (error) {
reject("Error extracting " + url + " - " + error);
})
.on("end", function () {
var successMessage = "Successfully downloaded and processed " + url;
const successMessage = "Successfully downloaded and processed " + url;

if (verify) {
verifyContents(verify)
Expand All @@ -83,7 +77,7 @@ function untgz(url, path, options) {
}
});

var gunzip = zlib.createGunzip().on("error", function (error) {
const gunzip = zlib.createGunzip().on("error", function (error) {
reject("Error decompressing " + url + " " + error);
});

Expand All @@ -97,58 +91,12 @@ function untgz(url, path, options) {
console.log("Downloading binaries from " + url);
}

axios
.get(url, { responseType: "stream" })
fetch(url)
.then((response) => {
response.data.pipe(gunzip).pipe(untar);
})
.catch((error) => {
if (verbose) {
console.error(error);
} else {
console.error(error.message);
}
});
});
}

function unzipUrl(url, path, options) {
options = options || {};

var verbose = options.verbose;
var verify = options.verify;

return new Promise(function (resolve, reject) {
var writeStream = unzip
.Extract({ path: path })
.on("error", function (error) {
reject("Error extracting " + url + " - " + error);
})
.on("entry", function (entry) {
console.log("Entry: " + entry.path);
})
.on("close", function () {
var successMessage = "Successfully downloaded and processed " + url;

if (verify) {
verifyContents(verify)
.then(function () {
resolve(successMessage);
})
.catch(reject);
} else {
resolve(successMessage);
if (!response.ok) {
throw new Error("HTTP error! status: " + response.status);
}
});

if (verbose) {
console.log("Downloading binaries from " + url);
}

axios
.get(url, { responseType: "stream" })
.then((response) => {
response.data.pipe(writeStream);
Readable.fromWeb(response.body).pipe(gunzip).pipe(untar);
})
.catch((error) => {
if (verbose) {
Expand Down
Loading