From 23dad990c42275fd0c66f4ab2bd2208f695a2873 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Tue, 19 Jul 2022 11:05:48 -0400 Subject: [PATCH] Adding NPM configuration for easier CI/CD install Signed-off-by: Dave Shanley Disabled test mode. Signed-off-by: Dave Shanley --- bin/vacuum.js | 16 ++ npm-install/config.js | 15 ++ npm-install/postinstall.js | 55 +++++++ package-lock.json | 293 +++++++++++++++++++++++++++++++++++++ package.json | 34 +++++ 5 files changed, 413 insertions(+) create mode 100644 bin/vacuum.js create mode 100644 npm-install/config.js create mode 100644 npm-install/postinstall.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/bin/vacuum.js b/bin/vacuum.js new file mode 100644 index 00000000..21faf766 --- /dev/null +++ b/bin/vacuum.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}/vacuum`), process.argv.slice(2), { + stdio: "inherit", + }); +} catch (e) { + exit(1) +} diff --git a/npm-install/config.js b/npm-install/config.js new file mode 100644 index 00000000..f1f03656 --- /dev/null +++ b/npm-install/config.js @@ -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", +}; \ No newline at end of file diff --git a/npm-install/postinstall.js b/npm-install/postinstall.js new file mode 100644 index 00000000..62ac2095 --- /dev/null +++ b/npm-install/postinstall.js @@ -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); + }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..644ba905 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,293 @@ +{ + "name": "vacuum", + "version": "0.0.12", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "vacuum", + "version": "0.0.12", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "node-fetch": "^3.1.0", + "tar": "^6.1.11", + "vacuum": "^0.1.3" + }, + "bin": { + "vacuum": "bin/vacuum.js" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "engines": { + "node": ">=10" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minipass": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.4.tgz", + "integrity": "sha512-I9WPbWHCGu8W+6k1ZiGpPu0GkoKBeorkfKNuAFBNS1HNFJvke82sxvI5bzcCNpWPorkOO5QQ+zomzzwRxejXiw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.2.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.9.tgz", + "integrity": "sha512-/2lI+DBecVvVm9tDhjziTVjo2wmTsSxSk58saUYP0P/fRJ3xxtfMDY24+CKTkfm0Dlhyn3CSXNL0SoRiCZ8Rzg==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/tar": { + "version": "6.1.11", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz", + "integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/vacuum": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/vacuum/-/vacuum-0.1.3.tgz", + "integrity": "sha512-rSmcte8bqlXGIJ+F+c00SYzVQ9e4Wgjeu2T4AiphGEhcIygNbVuvdAQHocmbGDsd1bkQ2qTiEuoVzitvxF3yAw==", + "engines": { + "node": "*" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "engines": { + "node": ">= 8" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + }, + "dependencies": { + "chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" + }, + "data-uri-to-buffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", + "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" + }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "requires": { + "fetch-blob": "^3.1.2" + } + }, + "fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "requires": { + "minipass": "^3.0.0" + } + }, + "minipass": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.4.tgz", + "integrity": "sha512-I9WPbWHCGu8W+6k1ZiGpPu0GkoKBeorkfKNuAFBNS1HNFJvke82sxvI5bzcCNpWPorkOO5QQ+zomzzwRxejXiw==", + "requires": { + "yallist": "^4.0.0" + } + }, + "minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "requires": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + } + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" + }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + }, + "node-fetch": { + "version": "3.2.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.9.tgz", + "integrity": "sha512-/2lI+DBecVvVm9tDhjziTVjo2wmTsSxSk58saUYP0P/fRJ3xxtfMDY24+CKTkfm0Dlhyn3CSXNL0SoRiCZ8Rzg==", + "requires": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + } + }, + "tar": { + "version": "6.1.11", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz", + "integrity": "sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA==", + "requires": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^3.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + } + }, + "vacuum": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/vacuum/-/vacuum-0.1.3.tgz", + "integrity": "sha512-rSmcte8bqlXGIJ+F+c00SYzVQ9e4Wgjeu2T4AiphGEhcIygNbVuvdAQHocmbGDsd1bkQ2qTiEuoVzitvxF3yAw==" + }, + "web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..5bc93ad3 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "@quobix/vacuum", + "version": "0.0.12", + "description": "The world's fastest, most scalable and complete OpenAPI parser", + "type": "module", + "author": "Dave Shanley", + "license": "MIT", + "homepage": "https://quobix.com/vacuum", + "repository": { + "type": "git", + "url": "git+https://github.com/daveshanley/vacuum.git" + }, + "engines": { + "node": ">=16.0.0" + }, + "scripts": { + "postinstall": "node ./npm-install/postinstall.js" + }, + "bin": { + "vacuum": "bin/vacuum.js" + }, + "files": [ + "npm-install" + ], + "dependencies": { + "node-fetch": "^3.1.0", + "tar": "^6.1.11", + "vacuum": "^0.1.3" + }, + "bugs": { + "url": "https://github.com/daveshanley/vacuum/issues" + }, + "main": "index.js" +}