UNPKG

947 BJavaScriptView Raw
1const Worker = require('./../class/Worker')
2const states = Worker.states
3const mergePorts = require('./../snippet/mergePorts')
4const AppStats = require('./../class/AppStats')
5
6module.exports = function list(config) {
7 return new Promise(resolve => {
8 const stats = {}
9
10 // show every started app (even if no workers are running)
11 config.apps.forEach(app => {
12 stats[app.name] = new AppStats(app.dir)
13 })
14
15 Worker.workerList.forEach(worker => {
16 // show stopped apps that have running workers
17 if (!stats[worker.name]) {
18 stats[worker.name] = new AppStats(worker.dir)
19 }
20
21 const appStats = stats[worker.name]
22
23 // increase state counter
24 const state = states[worker.state].toLowerCase()
25 appStats[state]++
26
27 // add ports
28 appStats.ports = mergePorts(appStats.ports, worker.ports)
29 })
30
31 resolve({
32 isResurrectable: global.isResurrectable,
33 stats
34 })
35 })
36}