Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Use binstall for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Nov 8, 2019
1 parent c3deb57 commit 8a42efd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 288 deletions.
26 changes: 26 additions & 0 deletions npm/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { Binary } = require("binary-install");
const os = require("os");
const { join } = require("path");
const platform = getPlatform();
const version = require("./package.json").version;
const url = `https://workers.cloudflare.com/get-npm-wrangler-binary/${version}/${platform}`;
const installDirectory = join(os.homedir(), ".wrangler");

function getPlatform() {
const type = os.type();
const arch = os.arch();

if (type === "Windows_NT" && arch === "x64") {
return "x86_64-pc-windows-msvc";
}
if (type === "Linux" && arch === "x64") {
return "x86_64-unknown-linux-musl";
}
if (type === "Darwin" && arch === "x64") {
return "x86_64-apple-darwin";
}

throw new Error(`Unsupported platform: ${type} ${arch}`);
}

module.exports.binary = new Binary({ name: "wrangler", url, installDirectory });
69 changes: 2 additions & 67 deletions npm/install-wrangler.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,2 @@
const axios = require("axios");
const os = require("os");
const { join, resolve } = require("path");
const { mkdirSync, existsSync } = require("fs");
const rimraf = require("rimraf");
const tar = require("tar");
const { get } = axios;
const { homedir } = require('os');

const cwd = join(homedir(), ".wrangler");

const VERSION = require("./package.json").version;

function getPlatform() {
const type = os.type();
const arch = os.arch();

if (type === "Windows_NT" && arch === "x64") {
return "x86_64-pc-windows-msvc";
}
if (type === "Linux" && arch === "x64") {
return "x86_64-unknown-linux-musl";
}
if (type === "Darwin" && arch === "x64") {
return "x86_64-apple-darwin";
}

throw new Error(`Unsupported platform: ${type} ${arch}`);
}

function downloadAsset(version, platform) {
const dest = join(cwd, "out");

if (existsSync(dest)) {
rimraf.sync(dest);
}
mkdirSync(dest);

const url = `https://workers.cloudflare.com/get-npm-wrangler-binary/${ version }/${ platform }`

console.log("Downloading release", url);

return axios({
url,
responseType: "stream"
}).then(res => {
res.data.pipe(
tar.x({
strip: 1,
C: dest
})
);
});
}

if (!existsSync(cwd)) {
mkdirSync(cwd);
}

downloadAsset(VERSION, getPlatform())
.then(() => {
console.log("Wrangler has been installed!");
})
.catch(e => {
console.error("Error fetching release", e.message);
throw e;
});
const { binary } = require("./binary");
binary.install();
195 changes: 0 additions & 195 deletions npm/npm-shrinkwrap.json

This file was deleted.

4 changes: 1 addition & 3 deletions npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
},
"homepage": "https://github.com/cloudflare/wrangler#readme",
"dependencies": {
"axios": "0.18.1",
"rimraf": "2.7.1",
"tar": "4.4.10"
"binary-install": "1.0.0"
},
"keywords": [
"wrangler",
Expand Down
25 changes: 2 additions & 23 deletions npm/run-wrangler.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
#!/usr/bin/env node

const { join } = require("path");
const { spawnSync } = require("child_process");
const { homedir } = require("os");

const cwd = join(homedir(), ".wrangler");
const bin = join(cwd, "out", "wrangler");
const [, , ...args] = process.argv;

const opts = {
cwd: process.cwd(),
stdio: "inherit"
};

const result = spawnSync(bin, args, opts);

if (result.error) {
console.error(result.error);
process.exit(1);
}

process.exit(result.status);
const { binary } = require("./binary");
binary.run();

0 comments on commit 8a42efd

Please sign in to comment.