| 1 |
#!/usr/bin/env node |
| 2 |
const fs = require('node:fs'); |
| 3 |
const path = require('node:path'); |
| 4 |
const { spawn } = require('node:child_process') |
| 5 |
|
| 6 |
// Platform distributed through NPM, this should mirror the package.json file list |
| 7 |
const executables = { |
| 8 |
'darwin-arm64': true, |
| 9 |
'darwin-x64': true, |
| 10 |
'linux-arm64': true, |
| 11 |
'linux-x64': true, |
| 12 |
'win32-ia32': true, |
| 13 |
'win32-x64': true |
| 14 |
}; |
| 15 |
|
| 16 |
const DIST = path.join(__dirname, 'dist'); |
| 17 |
const target = `${process.platform}-${process.arch}` |
| 18 |
|
| 19 |
const runChangie = (filename) => { |
| 20 |
const ext = process.platform === 'win32' ? '.exe' : ''; |
| 21 |
const executable = path.join(DIST, filename + ext); |
| 22 |
const stat = fs.statSync(executable) |
| 23 |
if (stat.isFile()) { |
| 24 |
const child = spawn(executable, process.argv.slice(2), { stdio: 'inherit' }); |
| 25 |
child.on('close', (code) => { |
| 26 |
process.exit(code); |
| 27 |
}); |
| 28 |
} else { |
| 29 |
throw new Error(`Unable to find changie ${executable} in NPM package`) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
if (executables[target]) { |
| 34 |
runChangie(target); |
| 35 |
} else { |
| 36 |
throw new Error(`Unsupported platform for Changie: ${target}`); |
| 37 |
} |