Skip to content

Commit

Permalink
chore: add bin path npm
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Oct 4, 2022
1 parent df9fd4e commit b7a71b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
31 changes: 24 additions & 7 deletions npm/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ const tarUrl = `https://github.com/adikari/safebox/releases/download/v${version}

if (!arch) {
error(`${name} is not supported for this architecture: ${arch}`);
return;
}

if (!platform) {
error(`${name} is not supported for this platform: ${platform}`);
return;
}

const nodeBin = path.join(__dirname, "../../.bin")
const bin = path.join(__dirname, "bin");

if (!fs.existsSync(nodeBin)){
fs.mkdirSync(nodeBin);
if (!fs.existsSync(bin)){
fs.mkdirSync(bin);
}

const error = msg => {
Expand All @@ -60,6 +58,8 @@ const install = () => {
const tarFile = `${tmpdir}/${name}.tar.gz`;
const download = fs.createWriteStream(tarFile);

console.log(`downloading safebox from ${tarUrl}`);

req.on('response', res => {
if (res.statusCode !== 200) {
error(`Error downloading safebox binary from ${tarUrl}. HTTP Status Code: ${res.statusCode}`);
Expand All @@ -70,8 +70,25 @@ const install = () => {

req.on('complete', () => {
cp.execSync(`tar -xf ${tarFile} -C ${tmpdir}`);
fs.copyFileSync(path.join(tmpdir, binaryName), path.join(nodeBin, binaryName));
fs.copyFileSync(path.join(tmpdir, binaryName), path.join(bin, binaryName));
});
};

install();
const uninstall = () => {
fs.unlinkSync(path.join(bin, binaryName));
}

let actions = {
"install": install,
"uninstall": uninstall
};

let argv = process.argv;
if (argv && argv.length > 2) {
let cmd = process.argv[2];
if (!actions[cmd]) {
error("Invalid command. `install` and `uninstall` are the only supported commands");
}

actions[cmd]();
}
7 changes: 5 additions & 2 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@adikari/safebox",
"version": "1.1.4",
"version": "1.1.5",
"description": "A Fast and Flexible secret manager built with love by adikari in Go",
"main": "index.js",
"bin": "./bin/safebox",
"scripts": {
"postinstall": "node install.js"
"postinstall": "node install.js install",
"preuninstall": "node install.js uninstall"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit b7a71b9

Please sign in to comment.