UNPKG

monex

Version:

Execute one or multiple scripts, interactively or in daemon mode, and restart them whenever they crash or a watched file changes.

38 lines (37 loc) 1.53 kB
/* IMPORT */ import Color from './color.js'; import ControllerSingle from './controller_single.js'; /* MAIN */ class ControllerMultiple { /* CONSTRUCTOR */ constructor(options) { /* API */ this.restart = async () => { await Promise.all(this.controllers.map(controller => controller.restart())); }; this.start = async () => { await Promise.all(this.controllers.map(controller => controller.start())); }; this.stat = async () => { return await Promise.all(this.controllers.map(controller => controller.stat())); }; this.stop = async () => { await Promise.all(this.controllers.map(controller => controller.stop())); }; this.options = options; this.controllers = this.options.exec.map((_, index) => { const prefix = true; const name = this.options.name?.[index] || String(index); const stdin = !this.options.restart || (this.options.restart === name); const color = Color.inferColor(index); const exec = this.options.exec[index]; const ignore = this.options.ignore; const watch = this.options.watch?.slice(index, index + 1); const cluster = this.options.cluster?.[index]; const delay = this.options.delay; return new ControllerSingle({ prefix, name, stdin, color, exec, ignore, watch, cluster, delay }); }); } } /* EXPORT */ export default ControllerMultiple;