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 6, 2024
1 parent 5a23864 commit db52e10
Showing 1 changed file with 43 additions and 20 deletions.
63 changes: 43 additions & 20 deletions npm/gild/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,51 @@
const { execSync } = require('child_process');
const os = require('os');
const fs = require('fs');
const path = require('path');

let binaryPath;

switch (os.platform().toString().trim()) {
case 'darwin':
let dariwinNpmGlobal = execSync("npm root -g").toString().trim();
binaryPath = os.arch() === 'x64'
? dariwinNpmGlobal +'/gild/node_modules/@samifouad/gild-darwin-x64/gild'
: dariwinNpmGlobal +'/gild/node_modules/@samifouad/gild-darwin-arm64/gild';
break;
case 'win32':
let winNpmGlobal = execSync("npm root -g").toString().trim();
binaryPath = winNpmGlobal +'\\gild\\node_modules\\@samifouad\\gild-windows-x64\\gild.exe';
break;
case 'linux':
let linuxNpmGlobal = execSync("npm root -g").toString().trim();
binaryPath = fs.realpathSync(linuxNpmGlobal +'/gild/node_modules/@samifouad/gild-linux-x64/gild');
break;
default:
console.error(`Unsupported platform: ${os.platform()}`);
// Determine if the script is running from a global installation or a local one
const isGlobalInstall = path.dirname(require.main.filename).includes('node_modules');

try {
let npmRoot;
if (isGlobalInstall) {
// Global install path
npmRoot = execSync("npm root -g").toString().trim();
} else {
// Local install path
npmRoot = path.dirname(require.main.filename);
}

const binaryName = os.platform() === 'win32' ? 'gild.exe' : 'gild';

switch (os.platform()) {
case 'darwin':
binaryPath = os.arch() === 'x64'
? path.join(npmRoot, 'gild', 'node_modules', '@samifouad', 'gild-darwin-x64', binaryName)
: path.join(npmRoot, 'gild', 'node_modules', '@samifouad', 'gild-darwin-arm64', binaryName);
break;
case 'win32':
binaryPath = path.join(npmRoot, 'gild', 'node_modules', '@samifouad', 'gild-windows-x64', binaryName);
break;
case 'linux':
binaryPath = path.join(npmRoot, 'gild', 'node_modules', '@samifouad', 'gild-linux-x64', binaryName);
break;
default:
console.error(`Unsupported platform: ${os.platform()}`);
process.exit(1);
}

// Check if the binary exists before trying to execute it
if (!fs.existsSync(binaryPath)) {
console.error(`Binary not found: ${binaryPath}`);
process.exit(1);
}
}

// Execute the binary with any arguments passed to the script
execSync(`"${binaryPath}" ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit' });
// Execute the binary with any arguments passed to the script
execSync(`"${binaryPath}" ${process.argv.slice(2).join(' ')}`, { stdio: 'inherit' });
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}

0 comments on commit db52e10

Please sign in to comment.