Skip to content

Commit

Permalink
gh workflow iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
samifouad committed Aug 7, 2024
1 parent 0bb14f9 commit f18831a
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions npm/gild/bin.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,64 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
const os = require('os');
const fs = require('fs');
const { execSync } = require('child_process')
const os = require('os')
const fs = require('fs')

let binaryPath;
let platform = os.platform().toString().trim()
let arch = os.arch()
let global = is_global()

switch (os.platform().toString().trim()) {
case 'darwin':
let dariwinNpmGlobal = execSync("npm root -g").toString().trim();
binaryPath = os.arch() === 'x64'
? dariwinNpmGlobal +'/@samifouad/node_modules/@samifouad/rexds-darwin-x64/gild'
: dariwinNpmGlobal +'/@samifouad/node_modules/@samifouad/rexds-darwin-arm64/gild';
if (global) {
let global_path = execSync("npm root -g").toString().trim()

switch (platform) {
case 'darwin':
binaryPath = os.arch() === 'x64'
? global_path +'/@samifouad/gild/node_modules/@samifouad/gild-darwin-x64/gild'
: global_path +'/@samifouad/gild/node_modules/@samifouad/gild-darwin-arm64/gild'
break;
case 'win32':
let winNpmGlobal = execSync("npm root -g").toString().trim();
binaryPath = winNpmGlobal +'\\@samifouad\\node_modules\\@samifouad\\rexds-windows-x64\\gild.exe';
case 'win32':
binaryPath = global_path +'\\@samifouad\\gild\\node_modules\\@samifouad\\gild-windows-x64\\gild.exe'
break;
case 'linux':
let linuxNpmGlobal = execSync("npm root -g").toString().trim();
binaryPath = fs.realpathSync(linuxNpmGlobal +'/@samifouad/node_modules/@samifouad/rexds-linux-x64/gild');
case 'linux':
binaryPath = fs.realpathSync(global_path +'/@samifouad/gild/node_modules/@samifouad/gild-linux-x64/gild')
break;
default:
console.error(`Unsupported platform: ${os.platform()}`);
process.exit(1);
}
default:
console.error(`Unsupported platform: ${os.platform()}`)
process.exit(1)
}

// Execute the binary with any arguments passed to the script
const args = process.argv.slice(2);
const processResult = spawnSync(binaryPath, args, { stdio: "inherit" });
process.exit(processResult.status ?? 0)

// Execute the binary with any arguments passed to the script
execSync(`"${binaryPath}" ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit' });
} else {

switch (platform) {
case 'darwin':
binaryPath = require.resolve(`gild-${os}-${arch}/gild`)
break;
case 'win32':
binaryPath = require.resolve(`gild-${os}-${arch}/gild.exe`)
break;
case 'linux':
binaryPath = require.resolve(`gild-${os}-${arch}/gild`)
break;
default:
console.error(`Unsupported platform: ${os.platform()}`)
process.exit(1)
}

// Execute the binary with any arguments passed to the script
const args = process.argv.slice(2);
const processResult = spawnSync(binaryPath, args, { stdio: "inherit" });
process.exit(processResult.status ?? 0)
}
function is_global() {
let globals = execSync("npm ls --depth=0 -global").toString();
if (globals.includes("@samifouad/gild")) {
return true
}
return false
}

0 comments on commit f18831a

Please sign in to comment.