UNPKG

881 BJavaScriptView Raw
1const AppStats = require('./../class/AppStats')
2const Worker = require('./../class/Worker')
3const states = Worker.states
4const mergePorts = require('./../snippet/mergePorts')
5
6module.exports = function info(config, command) {
7 return new Promise(resolve => {
8 const app = config.apps.find(app => app.name === command.app)
9
10 if (!app) {
11 throw new Error(`app "${command.app}" not found`)
12 }
13
14 const stats = new AppStats(app.dir)
15
16 // add general information
17 stats.name = app.name
18 stats.reviveCount = app.reviveCount || 0
19
20 const workers = Worker.workerList.filter(worker => worker.name === command.app)
21
22 workers.forEach(worker => {
23 // add worker states
24 const state = states[worker.state].toLowerCase()
25 stats[state]++
26 // add ports
27 stats.ports = mergePorts(stats.ports, worker.ports)
28 })
29
30 resolve(stats)
31 })
32}