Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
fix botway npm installer, update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed May 7, 2022
1 parent a050a1d commit da4000b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 58 deletions.
5 changes: 0 additions & 5 deletions installer/npm/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ export const CONFIG = {
*/
name: "botway",

/**
* @type {string}
*/
path: "./bin",

/**
* @type {string}
*/
Expand Down
51 changes: 39 additions & 12 deletions installer/npm/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { createWriteStream } from "fs";
import * as fs from "fs/promises";
import fetch from "node-fetch";
import { pipeline } from "stream/promises";
import zl from "zip-lib";

import StreamZip from "node-stream-zip";
import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js";
import path from "path";

async function install() {
const packageJson = await fs.readFile("package.json").then(JSON.parse);
Expand All @@ -17,31 +17,58 @@ async function install() {
if (version[0] === "v") version = version.slice(1);

// Fetch Static Config
let { name: binName, path: binPath, url } = CONFIG;
let { name: binName, url: url } = CONFIG;

url = url.replace(/{{arch}}/g, ARCH_MAPPING[process.arch]);
url = url.replace(/{{platform}}/g, PLATFORM_MAPPING[process.platform]);
url = url.replace(/{{version}}/g, version);
url = url.replace(/{{bin_name}}/g, binName);

const folder = (old) => {
let f =
binName +
"_" +
PLATFORM_MAPPING[process.platform] +
"_" +
"v" +
version +
"_" +
ARCH_MAPPING[process.arch];

if (old == "yes") {
return path.join(f, "bin");
} else if (old == "no") {
return "bin";
} else {
return f;
}
};

const response = await fetch(url);

console.log(response);

if (!response.ok) {
throw new Error("Failed fetching the binary: " + response.statusText);
}

const zipFile = "botway.zip";

await fs.mkdir(binPath, { recursive: true });
await pipeline(response.body, createWriteStream(zipFile));
zl.extract(zipFile, binPath).then(
function () {
console.log("done");
},
function (err) {
console.log(err);
}
);
const zip = new StreamZip.async({ file: zipFile });

const count = await zip.extract(null, ".");

console.log(`Extracted ${count} entries`);

await zip.close();

await fs.rename(folder("yes"), folder("no"), function (err) {
if (err) throw err;
});

await fs.rm(zipFile);
await fs.rm(folder(), { recursive: true });
}

install()
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"dependencies": {
"node-fetch": "^3.2.4",
"stream": "^0.0.2",
"zip-lib": "^0.7.3"
"node-stream-zip": "^1.15.0",
"stream": "^0.0.2"
}
}
43 changes: 4 additions & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
# yarn lockfile v1


buffer-crc32@~0.2.3:
version "0.2.13"
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
integrity sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=

data-uri-to-buffer@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b"
Expand All @@ -17,13 +12,6 @@ emitter-component@^1.1.1:
resolved "https://registry.yarnpkg.com/emitter-component/-/emitter-component-1.1.1.tgz#065e2dbed6959bf470679edabeaf7981d1003ab6"
integrity sha1-Bl4tvtaVm/RwZ57avq95gdEAOrY=

fd-slicer@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/fd-slicer/-/fd-slicer-1.1.0.tgz#25c7c89cb1f9077f8891bbe61d8f390eae256f1e"
integrity sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=
dependencies:
pend "~1.2.0"

fetch-blob@^3.1.2, fetch-blob@^3.1.4:
version "3.1.5"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.5.tgz#0077bf5f3fcdbd9d75a0b5362f77dbb743489863"
Expand Down Expand Up @@ -53,10 +41,10 @@ node-fetch@^3.2.4:
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"

pend@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50"
integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA=
node-stream-zip@^1.15.0:
version "1.15.0"
resolved "https://registry.yarnpkg.com/node-stream-zip/-/node-stream-zip-1.15.0.tgz#158adb88ed8004c6c49a396b50a6a5de3bca33ea"
integrity sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==

stream@^0.0.2:
version "0.0.2"
Expand All @@ -69,26 +57,3 @@ web-streams-polyfill@^3.0.3:
version "3.2.1"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6"
integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==

yauzl@^2.10.0:
version "2.10.0"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9"
integrity sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=
dependencies:
buffer-crc32 "~0.2.3"
fd-slicer "~1.1.0"

yazl@^2.5.1:
version "2.5.1"
resolved "https://registry.yarnpkg.com/yazl/-/yazl-2.5.1.tgz#a3d65d3dd659a5b0937850e8609f22fffa2b5c35"
integrity sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw==
dependencies:
buffer-crc32 "~0.2.3"

zip-lib@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/zip-lib/-/zip-lib-0.7.3.tgz#0f0c425569a79f7ef3641208bab53244ff23ff60"
integrity sha512-hp40KYzTJvoaCRr2t6hztlPnVmHYqDUDiIn0hlfAFwVBs3/jwkLy8aZ7NVGHECeWH2Tv8WPwWyR6QuWYarIjJQ==
dependencies:
yauzl "^2.10.0"
yazl "^2.5.1"

0 comments on commit da4000b

Please sign in to comment.