Add JS shim

This commit is contained in:
Evan 2023-10-16 22:03:22 -04:00
parent 6eb5d3c3c9
commit 1b658de968

39
invoke-binary.js Normal file
View file

@ -0,0 +1,39 @@
const childProcess = require('child_process')
const os = require('os')
const process = require('process')
function chooseBinary() {
const platform = os.platform()
const arch = os.arch()
if (platform === 'linux' && arch === 'x64') {
return `linux-amd64`
}
if (platform === 'linux' && arch === 'arm64') {
return `linux-arm64`
}
if (platform === 'windows' && arch === 'x64') {
return `windows-amd64.exe`
}
if (platform === 'windows' && arch === 'arm64') {
return `windows-arm64.exe`
}
console.error(`Unsupported platform (${platform}) and architecture (${arch})`)
process.exit(1)
}
function main() {
const binary = chooseBinary()
const mainScript = `${__dirname}/${binary}`
const spawnSyncReturns = childProcess.spawnSync(mainScript, { stdio: 'inherit' })
const status = spawnSyncReturns.status
if (typeof status === 'number') {
process.exit(status)
}
process.exit(1)
}
if (require.main === module) {
main()
}