From 7c49cfa0398a68c1ae67459c52f2a038845312c4 Mon Sep 17 00:00:00 2001 From: Vaddiraju Surya Teja Date: Tue, 14 May 2024 12:11:39 +0530 Subject: [PATCH] v2.0.8 - new version - Auto install viu binary --- .github/workflows/node.js.yml | 2 +- lib/postinstall.mjs | 56 +++++++---------------------------- lib/preinstall.mjs | 50 +++++++++++++++++++++++++++++++ package-lock.json | 8 ++--- package.json | 7 +++-- 5 files changed, 70 insertions(+), 53 deletions(-) create mode 100644 lib/preinstall.mjs diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8ed209b..3211b74 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,7 +12,7 @@ jobs: with: node-version: '20.x' registry-url: 'https://registry.npmjs.org' - - run: npm ci + - run: npm ci --ignore-scripts - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/lib/postinstall.mjs b/lib/postinstall.mjs index d95e48a..fe42511 100644 --- a/lib/postinstall.mjs +++ b/lib/postinstall.mjs @@ -1,51 +1,17 @@ -import * as fs from "node:fs"; -import https from 'node:https'; +import {existsSync,chmodSync} from "node:fs"; let package_name = ""; -let offline_file = "viu"; -if (process.platform==='darwin'&& process.arch==='x64'){ - package_name = "viu-x86_64-apple-darwin" +if (!existsSync("./bin")) { + throw new Error("Platform not supported, Request to manually download the viu from rust standard installation page and place it in your system environment variables.") } -else if (process.platform==='win32'&& process.arch==='x64'){ - package_name = "viu-x86_64-pc-windows-msvc.exe"; - offline_file = "viu.exe"; -} -else if (process.platform==='linux'&& process.arch==='x64'){ - package_name = "viu-x86_64-unknown-linux-musl" -} -else if (process.platform==='linux'&& process.arch==='arm64'){ - package_name = "viu-aprocess.arch64-unknown-linux-musl" -} -else if (process.platform==='linux'&& process.arch==='arm' && process.config.variables.arm_version === 7){ - package_name = "viu-armv7-unknown-linux-musleabihf" -} -else if(process.platform==='linux'&& process.arch==='arm' && process.config.variables.arm_version !== 7){ - package_name = "viu-arm-unknown-linux-musleabihf" +if (process.platform==='win32'&& process.arch==='x64'){ + package_name = "./bin/viu.exe"; } else{ - throw new Error("Platform not supported, Request to manually download the viu fromrust standard installation page and place it in the bin folder.") + package_name = "./bin/viu"; } -const url = `https://github.com/atanunq/viu/releases/latest/download/${package_name}`; -function download(url, dest) { - const req = https.get(url); - req.on('response', (res) => { - if (res.statusCode === 200) { - res.pipe(dest); - } - else if (res.statusCode === 302 || res.statusCode === 301) { - download(res.headers.location, dest); - } - else{ - console.error('Failed to download:', res.statusCode, res.statusMessage); - } - }); -}; -if (!fs.existsSync("./bin")) { - fs.mkdirSync("./bin"); +if (!existsSync(package_name)){ + throw new Error("Platform not supported, Request to manually download the viu from rust standard installation page and place it in your system environment variables.") } -const binaryPath = `./bin/${offline_file}`; -if (!fs.existsSync(binaryPath)) { - fs.closeSync(fs.openSync(binaryPath, 'w')); - const file = fs.createWriteStream(binaryPath); - download(url,file); - fs.chmodSync(binaryPath, 0o755); -}; \ No newline at end of file +else{ + chmodSync(package_name, 0o755); +} \ No newline at end of file diff --git a/lib/preinstall.mjs b/lib/preinstall.mjs new file mode 100644 index 0000000..3058a09 --- /dev/null +++ b/lib/preinstall.mjs @@ -0,0 +1,50 @@ +import * as fs from "node:fs"; +import https from 'node:https'; +let package_name = ""; +let offline_file = "viu"; +if (process.platform==='darwin'&& process.arch==='x64'){ + package_name = "viu-x86_64-apple-darwin" +} +else if (process.platform==='win32'&& process.arch==='x64'){ + package_name = "viu-x86_64-pc-windows-msvc.exe"; + offline_file = "viu.exe"; +} +else if (process.platform==='linux'&& process.arch==='x64'){ + package_name = "viu-x86_64-unknown-linux-musl" +} +else if (process.platform==='linux'&& process.arch==='arm64'){ + package_name = "viu-aprocess.arch64-unknown-linux-musl" +} +else if (process.platform==='linux'&& process.arch==='arm' && process.config.variables.arm_version === 7){ + package_name = "viu-armv7-unknown-linux-musleabihf" +} +else if(process.platform==='linux'&& process.arch==='arm' && process.config.variables.arm_version !== 7){ + package_name = "viu-arm-unknown-linux-musleabihf" +} +else{ + throw new Error("Platform not supported, Request to manually download the viu fromrust standard installation page and place it in the bin folder.") +} +const url = `https://github.com/atanunq/viu/releases/latest/download/${package_name}`; +function download(url, dest) { + const req = https.get(url); + req.on('response', (res) => { + if (res.statusCode === 200) { + res.pipe(dest); + } + else if (res.statusCode === 302 || res.statusCode === 301) { + download(res.headers.location, dest); + } + else{ + console.error('Failed to download:', res.statusCode, res.statusMessage); + } + }); +}; +if (!fs.existsSync("./bin")) { + fs.mkdirSync("./bin"); +} +const binaryPath = `./bin/${offline_file}`; +if (!fs.existsSync(binaryPath)) { + fs.closeSync(fs.openSync(binaryPath, 'w')); + const file = fs.createWriteStream(binaryPath); + download(url,file); +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bbf8668..d1b5cdb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "irctc-api", - "version": "2.0.7", + "version": "2.0.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "irctc-api", - "version": "2.0.7", + "version": "2.0.8", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "axios": "^1.6.8", - "axios-cookiejar-support": "^5.0.1", + "axios-cookiejar-support": "^5.0.2", "cheerio": "^1.0.0-rc.12", - "tough-cookie": "^4.1.3" + "tough-cookie": "^4.1.4" }, "bin": { "viu": "bin/viu" diff --git a/package.json b/package.json index e8f93da..a2175f8 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "irctc-api", "description": "An exclusive NodeJs only package built on top of IRCTC Website APIs to book train tickets, managing user profile faster and simpler from anywhere in the world", - "version": "2.0.7", + "version": "2.0.8", "scripts": { + "preinstall": "node ./lib/preinstall.mjs", "postinstall": "node ./lib/postinstall.mjs", "test": "echo \"Error: no test specified\" && exit 1" }, @@ -59,9 +60,9 @@ ], "dependencies": { "axios": "^1.6.8", - "axios-cookiejar-support": "^5.0.1", + "axios-cookiejar-support": "^5.0.2", "cheerio": "^1.0.0-rc.12", - "tough-cookie": "^4.1.3" + "tough-cookie": "^4.1.4" }, "engines": { "node": ">20.0.0",