github-desktop/script/run.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-12-24 16:26:17 +00:00
import { join } from 'path'
import { spawn, SpawnOptions } from 'child_process'
2018-05-21 06:29:48 +00:00
import * as Fs from 'fs'
2017-12-24 16:26:17 +00:00
import { getDistPath, getExecutableName } from './dist-info'
const distPath = getDistPath()
const productName = getExecutableName()
let binaryPath = ''
if (process.platform === 'darwin') {
binaryPath = join(
distPath,
`${productName}.app`,
'Contents',
'MacOS',
`${productName}`
)
} else if (process.platform === 'win32') {
binaryPath = join(distPath, `${productName}.exe`)
} else if (process.platform === 'linux') {
binaryPath = join(distPath, productName)
2018-05-05 21:10:55 +00:00
} else {
2017-12-24 16:26:17 +00:00
console.error(`I dunno how to run on ${process.platform} ${process.arch} :(`)
process.exit(1)
}
export function run(spawnOptions: SpawnOptions) {
try {
2018-05-21 06:29:48 +00:00
// eslint-disable-next-line no-sync
const stats = Fs.statSync(binaryPath)
2017-12-24 16:26:17 +00:00
if (!stats.isFile()) {
return null
}
} catch (e) {
return null
}
const opts = Object.assign({}, spawnOptions)
opts.env = Object.assign(opts.env || {}, process.env, {
NODE_ENV: 'development',
})
return spawn(binaryPath, [], opts)
}