Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Update NPM to use zipped files
Browse files Browse the repository at this point in the history
Update NPM to use zipped files

Update NodeJS to use zipped files

Release for npm distribution test

Allow user to execute kamda on install

Release for npm distribution test

Release yarn installable version

Rename arhive extension to zip
  • Loading branch information
mainawycliffe committed May 31, 2020
1 parent ac1a50c commit e2863ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
31 changes: 11 additions & 20 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol

var request = require("request"),
path = require("path"),
tar = require("tar"),
zlib = require("zlib"),
unzipper = require("unzipper"),
mkdirp = require("mkdirp"),
fs = require("fs"),
exec = require("child_process").exec;
Expand All @@ -31,11 +30,11 @@ var PLATFORM_MAPPING = {
function getInstallationPath(callback) {
// `$npm_execpath bin` will output the path where binary files should be installed
// using whichever package manager is current
var packageManager = process.env.npm_execpath || "npm";
console.log({ packageManager: packageManager });
var execPath = process.env.npm_execpath;
var packageManager = execPath && execPath.includes("yarn") ? "yarn global" : "npm";
exec(packageManager + " bin", function (err, stdout, stderr) {
var dir = null;
if (err || stderr || !stdout || stdout.length === 0) {
if (err || stderr && !stderr.includes("No license field") || !stdout || stdout.length === 0) {
// We couldn't infer path from `npm bin`. Let's try to get it from
// Environment variables set by NPM when it runs.
// npm_config_prefix points to NPM's installation directory where `bin` folder is available
Expand All @@ -48,7 +47,6 @@ function getInstallationPath(callback) {
dir = stdout.trim();
}

console.log({ dir: dir });
mkdirp.sync(dir);

callback(null, dir);
Expand Down Expand Up @@ -157,25 +155,18 @@ function install(callback) {
if (!opts) {
return callback("Invalid inputs");
}
console.log({ opts: opts });
mkdirp.sync(opts.binPath);
var ungz = zlib.createGunzip();
var untar = tar.Extract({ path: opts.binPath });

ungz.on("error", callback);
untar.on("error", callback);

// First we will Un-GZip, then we will untar. So once untar is completed,
// binary is downloaded into `binPath`. Verify the binary and call it good
untar.on("end", verifyAndPlaceBinary.bind(null, opts.binName, opts.binPath, callback));

console.log("Downloading from URL: " + opts.url);
var req = request({ uri: opts.url });
req.on("error", callback.bind(null, "Error downloading from URL: " + opts.url));
req.on("response", function (res) {
if (res.statusCode !== 200) return callback("Error downloading binary. HTTP Status Code: " + res.statusCode);

req.pipe(ungz).pipe(untar);
if (res.statusCode !== 200) {
return callback("Error downloading binary. HTTP Status Code: " + res.statusCode);
}
req.pipe(unzipper.Extract({ path: opts.binPath })).on("error", callback)
// First we will Un-GZip, then we will untar. So once untar is completed,
// binary is downloaded into `binPath`. Verify the binary and call it good
.on("close", verifyAndPlaceBinary.bind(null, opts.binName, opts.binPath, callback));
});
}

Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,18 @@ function install(callback) {
);
}
req
.pipe(unzipper.Extract({ path: opts.binPath }))
// parse and save file
.pipe(unzipper.Parse())
.on("entry", function (entry) {
const fileName = entry.path;
if (fileName === "kamanda") {
entry.pipe(
fs.createWriteStream(opts.binPath + "/kamanda", { mode: 755 })
);
} else {
entry.autodrain();
}
})
.on("error", callback)
// First we will Un-GZip, then we will untar. So once untar is completed,
// binary is downloaded into `binPath`. Verify the binary and call it good
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kamanda",
"version": "0.4.2-6",
"version": "0.4.2",
"description": "Kamanda - A Firebase CLI Companion Tool",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -42,6 +42,6 @@
"goBinary": {
"name": "kamanda",
"path": "./bin",
"url": "https://github.com/mainawycliffe/kamanda/releases/download/v{{version}}/kamanda_{{version}}_{{platform}}_{{arch}}.tar.gz"
"url": "https://github.com/mainawycliffe/kamanda/releases/download/v{{version}}/kamanda_{{version}}_{{platform}}_{{arch}}.zip"
}
}

0 comments on commit e2863ba

Please sign in to comment.