-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding NPM configuration for easier CI/CD install
Signed-off-by: Dave Shanley <[email protected]> Disabled test mode. Signed-off-by: Dave Shanley <[email protected]>
- Loading branch information
1 parent
a84868e
commit 23dad99
Showing
5 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}/vacuum`), process.argv.slice(2), { | ||
stdio: "inherit", | ||
}); | ||
} catch (e) { | ||
exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const CONFIG = { | ||
name: "vacuum", | ||
path: "./bin", | ||
url: "https://github.com/daveshanley/vacuum/releases/download/v{{version}}/{{bin_name}}_{{version}}_{{platform}}_{{arch}}.tar.gz", | ||
}; | ||
export const ARCH_MAPPING = { | ||
ia32: "386", | ||
x64: "amd64", | ||
arm64: "arm64", | ||
}; | ||
export const PLATFORM_MAPPING = { | ||
darwin: "darwin", | ||
linux: "linux", | ||
win32: "windows", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createWriteStream } from "fs"; | ||
import * as fs from "fs/promises"; | ||
import fetch from "node-fetch"; | ||
import { pipeline } from "stream/promises"; | ||
import tar from "tar"; | ||
import { execSync } from "child_process"; | ||
|
||
import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js"; | ||
|
||
async function install() { | ||
if (process.platform === "android") { | ||
console.log("Installing, may take a moment..."); | ||
const cmd = | ||
"pkg upgrade && pkg install golang git -y && git clone https://github.com/daveshanley/vacuum.git && cd cli/ && go build -o $PREFIX/bin/vacuum"; | ||
execSync(cmd, { encoding: "utf-8" }); | ||
console.log("Installation successful!"); | ||
return; | ||
} | ||
const packageJson = await fs.readFile("package.json").then(JSON.parse); | ||
let version = packageJson.version; | ||
|
||
if (typeof version !== "string") { | ||
throw new Error("Missing version in package.json"); | ||
} | ||
|
||
if (version[0] === "v") version = version.slice(1); | ||
|
||
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]); | ||
url = url.replace(/{{version}}/g, version); | ||
url = url.replace(/{{bin_name}}/g, binName); | ||
|
||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error("Failed fetching the binary: " + response.statusText); | ||
} | ||
|
||
const tarFile = "downloaded.tar.gz"; | ||
|
||
await fs.mkdir(binPath, { recursive: true }); | ||
await pipeline(response.body, createWriteStream(tarFile)); | ||
await tar.x({ file: tarFile, cwd: binPath }); | ||
await fs.rm(tarFile); | ||
} | ||
|
||
install() | ||
.then(async () => { | ||
process.exit(0); | ||
}) | ||
.catch(async (err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.