UNPKG

create-js-app-scripts

Version:
57 lines (41 loc) 1.42 kB
'use strict'; const path = require('path'); const loadConfiguration = require('./utils/loadConfiguration'); class Environment { constructor(cwd, configFileName = '.app.js', logger) { this.cwd = cwd; this.configFileName = configFileName; this.logger = logger; } configFilePath() { return path.resolve(this.cwd, this.configFileName); } getConfiguration() { return loadConfiguration(this); } getName() { return this.getConfiguration().env.NODE_ENV; } async build() { const config = loadConfiguration(this); // run build phase on plugins (do not instantiate them) const pluginControllers = await Promise.all(config.plugins.map(plugin => plugin(this, true, this.logger))); await Promise.all(pluginControllers.map(pluginController => pluginController.build())); } async start() { const config = loadConfiguration(this); // instantiate plugins this.plugins = await Promise.all(config.plugins.map(plugin => plugin(this, false, this.logger))); await Promise.all(this.plugins.map(p => p.start())); } async restart() { // terminate all plugins await Promise.all(this.plugins.map(pluginController => pluginController.terminate())); // start all plugins await this.start(); } async stop() { await Promise.all(this.plugins.map(pluginController => pluginController.terminate())); } } module.exports = Environment;