1 | const startWorkers = require('./../module/startWorkers')
|
2 | const getPack = require('./../module/getPack')
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | module.exports = function start(config, command) {
|
19 | return new Promise((resolve, reject) => {
|
20 | if (global.isResurrectable) {
|
21 | global.isResurrectable = false
|
22 | config.apps = []
|
23 | }
|
24 |
|
25 |
|
26 | const pack = getPack(command.dir, command.opt, command.env)
|
27 |
|
28 |
|
29 | if (config.apps.some(app => app.name === pack.name)) {
|
30 | throw new Error(`an app called "${pack.name}" is already running.`)
|
31 | }
|
32 |
|
33 | config.apps.push({
|
34 | dir: command.dir,
|
35 | name: pack.name,
|
36 | args: command.args,
|
37 | opt: command.opt,
|
38 | env: command.env
|
39 | })
|
40 |
|
41 | return startWorkers(config, command.dir, pack, command.args, command.env).then(resolve).catch(err => {
|
42 |
|
43 | const i = config.apps.findIndex(app => app.name === pack.name)
|
44 | if (i !== -1) {
|
45 | config.apps.splice(i, 1)
|
46 | }
|
47 |
|
48 | reject(err)
|
49 | })
|
50 | })
|
51 | }
|