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

Commit

Permalink
more fixes and changes for botway npm installer
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed May 8, 2022
1 parent 796e96f commit 61c6d16
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
16 changes: 16 additions & 0 deletions bin/botway.js
Original file line number Diff line number Diff line change
@@ -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);
}
12 changes: 0 additions & 12 deletions installer/npm/botway.js

This file was deleted.

5 changes: 5 additions & 0 deletions installer/npm/config.js → npm-installer/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const CONFIG = {
*/
name: "botway",

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

/**
* @type {string}
*/
Expand Down
14 changes: 4 additions & 10 deletions installer/npm/postinstall.js → npm-installer/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -36,24 +36,23 @@ 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;
}
};

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 });

Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 61c6d16

Please sign in to comment.