Skip to content

Commit

Permalink
Merge pull request #42 from suryavaddiraju/development
Browse files Browse the repository at this point in the history
v2.0.10
  • Loading branch information
suryavaddiraju authored May 14, 2024
2 parents 1a73f01 + 7b42f2c commit f207082
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 71 deletions.
25 changes: 25 additions & 0 deletions lib/cli-wrapper.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {execFile} from "node:child_process";
import { fileURLToPath } from 'node:url';
import {readdirSync} from "node:fs";
import { dirname,join } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const path_l = join(__dirname, "..","bin");
const files = readdirSync(path_l);
const args = process.argv.slice(2);
let path_n = "";
if (files.length === 0) {
throw new Error("Platform not supported, Request you to manually download the viu binary file from rust standard installation page and place it inside this bin folder located in. "+path_l)
}
else{
path_n = files[0];
}
const binaryPath = join(path_l, path_n);
execFile(binaryPath,args, (error, stdout, stderr) => {
stdout: console.log(stdout);
stderr: console.error(stderr);
if (error) {
console.error(`exec error: ${error}`);
return;
}
});
57 changes: 46 additions & 11 deletions lib/postinstall.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,52 @@
import {existsSync,chmodSync} from "node:fs";
import * as fs from "node:fs";
import https from 'node:https';
let package_name = "";
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.")
let offline_file = "viu";
if (process.platform==='darwin'&& process.arch==='x64'){
package_name = "viu-x86_64-apple-darwin"
}
if (process.platform==='win32'&& process.arch==='x64'){
package_name = "./bin/viu.exe";
else if (process.platform==='win32'&& process.arch==='x64'){
package_name = "viu-x86_64-pc-windows-msvc.exe";
offline_file = "viu.exe";
}
else{
package_name = "./bin/viu";
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"
}
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.")
else if(process.platform==='linux'&& process.arch==='arm' && process.config.variables.arm_version !== 7){
package_name = "viu-arm-unknown-linux-musleabihf"
}
else{
chmodSync(package_name, 0o755);
}
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("./lib/cli-wrapper.mjs", 0o755);
fs.chmodSync(binaryPath, 0o755);
};
55 changes: 0 additions & 55 deletions lib/preinstall.mjs

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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.9",
"version": "2.0.10",
"scripts": {
"preinstall": "node ./lib/preinstall.mjs",
"postinstall": "node ./lib/postinstall.mjs",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -13,7 +12,7 @@
},
"license": "Apache-2.0",
"bin": {
"viu": "./bin/viu"
"viu": "./lib/cli-wrapper.mjs"
},
"keywords": [
"irctc",
Expand Down

0 comments on commit f207082

Please sign in to comment.