From 61c6d164cc6276a59e170d1166b07125c823ee87 Mon Sep 17 00:00:00 2001 From: abdfnx Date: Sun, 8 May 2022 13:34:51 +0300 Subject: [PATCH] more fixes and changes for botway npm installer --- bin/botway.js | 16 ++++++++++++++++ installer/npm/botway.js | 12 ------------ {installer/npm => npm-installer}/config.js | 5 +++++ {installer/npm => npm-installer}/postinstall.js | 14 ++++---------- package.json | 6 +++--- 5 files changed, 28 insertions(+), 25 deletions(-) create mode 100755 bin/botway.js delete mode 100755 installer/npm/botway.js rename {installer/npm => npm-installer}/config.js (87%) rename {installer/npm => npm-installer}/postinstall.js (84%) diff --git a/bin/botway.js b/bin/botway.js new file mode 100755 index 00000000..ce342f9b --- /dev/null +++ b/bin/botway.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node +import { execFileSync } from "child_process"; +import path from "path"; +import { exit } from "process"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +try { + execFileSync(path.resolve(`${__dirname}/botway`), process.argv.slice(2), { + stdio: "inherit", + }); +} catch (e) { + exit(1); +} diff --git a/installer/npm/botway.js b/installer/npm/botway.js deleted file mode 100755 index 0d722612..00000000 --- a/installer/npm/botway.js +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env node -import { execFileSync } from "child_process"; -import { exit } from "process"; - -try { - execFileSync("./botwaybin", process.argv.slice(2), { - stdio: "inherit", - }); -} catch (e) { - console.log(e); - exit(1); -} diff --git a/installer/npm/config.js b/npm-installer/config.js similarity index 87% rename from installer/npm/config.js rename to npm-installer/config.js index 141a542d..0893b019 100755 --- a/installer/npm/config.js +++ b/npm-installer/config.js @@ -7,6 +7,11 @@ export const CONFIG = { */ name: "botway", + /** + * @type {string} + */ + path: "./bin", + /** * @type {string} */ diff --git a/installer/npm/postinstall.js b/npm-installer/postinstall.js similarity index 84% rename from installer/npm/postinstall.js rename to npm-installer/postinstall.js index 27414d4a..d081d068 100755 --- a/installer/npm/postinstall.js +++ b/npm-installer/postinstall.js @@ -17,7 +17,7 @@ async function install() { if (version[0] === "v") version = version.slice(1); // Fetch Static Config - let { name: binName, url: url } = CONFIG; + let { name: binName, path: binPath, url } = CONFIG; url = url.replace(/{{arch}}/g, ARCH_MAPPING[process.arch]); url = url.replace(/{{platform}}/g, PLATFORM_MAPPING[process.platform]); @@ -36,9 +36,9 @@ async function install() { ARCH_MAPPING[process.arch]; if (old == "yes") { - return path.join(f, "bin"); + return path.join(f, "bin", "botway"); } else if (old == "no") { - return "bbin"; + return path.join("bin", "botway"); } else { return f; } @@ -46,14 +46,13 @@ async function install() { 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)); const zip = new StreamZip.async({ file: zipFile }); @@ -67,13 +66,8 @@ async function install() { if (err) throw err; }); - await fs.rename("bbin/botway", "botwaybin", function (err) { - if (err) throw err; - }); - await fs.rm(zipFile); await fs.rm(folder(), { recursive: true }); - await fs.rm("bbin", { recursive: true }); } install() diff --git a/package.json b/package.json index 474fcc37..38d3ebdd 100644 --- a/package.json +++ b/package.json @@ -14,13 +14,13 @@ "node": ">=8.0.0" }, "bin": { - "botway": "installer/npm/botway.js" + "botway": "npm-installer/bin/botway.js" }, "scripts": { - "postinstall": "node ./installer/npm/postinstall.js" + "postinstall": "node ./npm-installer/postinstall.js" }, "files": [ - "installer/npm" + "npm-installer" ], "dependencies": { "node-fetch": "^3.2.4",