forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
44 lines (37 loc) · 962 Bytes
/
run.js
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
'use strict'
const path = require('path')
const cp = require('child_process')
const fs = require('fs')
const distInfo = require('./dist-info')
const distPath = distInfo.getDistPath()
const productName = distInfo.getProductName()
let binaryPath = ''
if (process.platform === 'darwin') {
binaryPath = path.join(
distPath,
`${productName}.app`,
'Contents',
'MacOS',
`${productName}`
)
} else if (process.platform === 'win32') {
binaryPath = path.join(distPath, `${productName}.exe`)
} else {
console.error(`I dunno how to run on ${process.arch} :(`)
process.exit(1)
}
module.exports = function(spawnOptions) {
try {
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 cp.spawn(binaryPath, [], opts)
}