-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dave Shanley <dave@quobix.com>
- Loading branch information
1 parent
9fa9989
commit 30850e5
Showing
4 changed files
with
306 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,15 @@ | ||
export const CONFIG = { | ||
name: "wiretap", | ||
path: "./bin", | ||
url: "https://github.com/pb33f/wiretap/releases/download/v{{version}}/{{bin_name}}_{{version}}_{{platform}}_{{arch}}.tar.gz", | ||
}; | ||
export const ARCH_MAPPING = { | ||
ia32: "i386", | ||
x64: "x86_64", | ||
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,57 @@ | ||
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/pb33f/wiertap.git && make build"; | ||
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); | ||
|
||
|
||
console.log('fetching from URL', url) | ||
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.
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,33 @@ | ||
{ | ||
"name": "@pb33f/wiretap", | ||
"version": "0.0.0", | ||
"description": "The world's coolest OpenAPI compliance API Proxy in the world", | ||
"type": "module", | ||
"author": "Princess Beef Heavy Industries, LLC / Quobix", | ||
"license": "GPL-3.0", | ||
"homepage": "https://pb33f.io/wiretap", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/pb33f/wiretap.git" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"scripts": { | ||
"postinstall": "node ./npm-install/postinstall.js" | ||
}, | ||
"bin": { | ||
"wiretap": "bin/wiretap.js" | ||
}, | ||
"files": [ | ||
"npm-install" | ||
], | ||
"dependencies": { | ||
"node-fetch": "^3.2.10", | ||
"tar": "^6.1.11" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/pb33f/wiretap/issues" | ||
}, | ||
"main": "index.js" | ||
} |