-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |