forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.ts
45 lines (39 loc) · 1.08 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { join } from 'path'
import { spawn, SpawnOptions } from 'child_process'
import * as Fs from 'fs'
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)
} else {
console.error(`I dunno how to run on ${process.platform} ${process.arch} :(`)
process.exit(1)
}
export function run(spawnOptions: SpawnOptions) {
try {
// eslint-disable-next-line no-sync
const stats = Fs.statSync(binaryPath)
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)
}