UNPKG

monex

Version:

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

50 lines (49 loc) 1.29 kB
/* IMPORT */ import process from 'node:process'; import execute from './/index.js'; /* MAIN */ class ControllerDaemon { constructor() { /* VARIABLES */ this.controllers = []; /* API */ this.kill = async () => { await this.stop(); process.exit(0); }; this.ping = async () => { return; }; this.start = async (config) => { await this.stop(); try { config.forEach(options => { const controller = execute(options); this.controllers.push(controller); }); return true; } catch { return false; } }; this.stat = async () => { try { return (await Promise.all(this.controllers.map(controller => controller.stat()))).flat(); } catch { return []; } }; this.stop = async () => { try { await Promise.all(this.controllers.map(controller => controller.stop())); } catch { } this.controllers = []; }; } } ; /* EXPORT */ export default ControllerDaemon;