diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 14d6bd2..ea1de02 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -9,9 +9,9 @@ following additional notes. ## Questions The GitHub issue tracker is for *bug reports* and *feature requests*. Please do -not use it to ask questions about how to use Requests. These questions should +not use it to ask questions about how to use irctc-api. These questions should instead be directed to [Stack Overflow](https://stackoverflow.com/). Make sure -that your question is tagged with the `node-irctc-api` tag when asking it on +that your question is tagged with the `node.js & api` tag when asking it on Stack Overflow, to ensure that it is answered promptly and accurately. ## Good Bug Reports diff --git a/.npmignore b/.npmignore index 87bbfe8..01e8421 100644 --- a/.npmignore +++ b/.npmignore @@ -5,4 +5,10 @@ test/ api_reference.md contribution.md _config.yml -captcha.jpg \ No newline at end of file +captcha.jpg +captcha.jpg +viu +bin +viu.exe +.log +logs \ No newline at end of file diff --git a/_config.yml b/_config.yml index e42f909..daf2cc0 100644 --- a/_config.yml +++ b/_config.yml @@ -5,4 +5,4 @@ author: remote_theme: jekyll/minima plugins: - jekyll-remote-theme -exclude: [lib/,examples/,test/,.gitignore,.npmignore,index.mjs,LICENSE,package.json,.github/,package-lock.json,_config.yml] \ No newline at end of file +exclude: [lib/,examples/,test/,.gitignore,.npmignore,index.mjs,LICENSE,package.json,.github/,package-lock.json,_config.yml,"bin/"] \ No newline at end of file diff --git a/lib/postinstall.mjs b/lib/postinstall.mjs index 606e04c..30f0032 100644 --- a/lib/postinstall.mjs +++ b/lib/postinstall.mjs @@ -1,4 +1,52 @@ import * as fs from "node:fs"; -const JSON_data = JSON.parse(fs.readFileSync("./package.json")); -const path = JSON_data.bin.viu; -fs.chmodSync(path, 0o755); \ No newline at end of file +import https from 'node:https'; +import * as fs from 'node:fs'; +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); + fs.chmodSync(binaryPath, 0o755); +}; \ No newline at end of file diff --git a/lib/preinstall.mjs b/lib/preinstall.mjs deleted file mode 100644 index 3280566..0000000 --- a/lib/preinstall.mjs +++ /dev/null @@ -1,57 +0,0 @@ -import https from 'node:https'; -import * as fs from 'node:fs'; -import * as path from 'path'; -import {exec} from 'node:child_process'; -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") -} -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); - const JSON_data = JSON.parse(fs.readFileSync("./package.json")) - if (JSON_data.bin.viu !== binaryPath){ - JSON_data.bin.viu = binaryPath; - fs.writeFileSync("./package.json", JSON.stringify(JSON_data, null, 2)); - } -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8cb21d5..2f84eb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "irctc-api", - "version": "2.0.5", + "version": "2.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "irctc-api", - "version": "2.0.5", + "version": "2.0.6", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 548e60b..7b8345e 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,8 @@ { "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.5", + "version": "2.0.6", "scripts": { - "preinstall": "node ./lib/preinstall.mjs", "postinstall": "node ./lib/postinstall.mjs", "test": "echo \"Error: no test specified\" && exit 1" },