UNPKG

pandora

Version:

A powerful and lightweight application manager for Node.js applications powered by TypeScript.

55 lines 2.35 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const ApplicationHandler_1 = require("../application/ApplicationHandler"); const pandora_dollar_1 = require("pandora-dollar"); const CoreSDKWithExtendedConfig_1 = require("../util/CoreSDKWithExtendedConfig"); /** * Class FrontApplicationLoader */ class FrontApplicationLoader { constructor(representation) { this.representation = Object.assign(Object.assign({}, representation), { appName: representation.appName || 'unnamed' }); const { appName, appDir } = this.representation; this.coreSdk = new CoreSDKWithExtendedConfig_1.CoreSDKWithExtendedConfig({ mode: 'supervisor', appName, appDir }); this.applicationHandler = new ApplicationHandler_1.ApplicationHandler(this.representation); } /** * Start * @return {Promise<void>} */ async start() { const representation = this.representation; if (representation.appDir !== process.cwd()) { process.chdir(representation.appDir); pandora_dollar_1.consoleLogger.info('Switch current working dir to ' + representation.appDir); } await this.coreSdk.start(); const onProcessTerm = (sig) => { pandora_dollar_1.consoleLogger.log(); pandora_dollar_1.consoleLogger.important(`Receive a signal ${sig}, trying to stop...`); this.stop().then(() => { process.exit(0); }).catch((err) => { pandora_dollar_1.consoleLogger.error(err); process.exit(1); }); }; this.applicationHandler.start().then(() => { pandora_dollar_1.consoleLogger.important(`Application [name = ${representation.appName}] start successful.`); process.once('SIGQUIT', onProcessTerm.bind(null, 'SIGQUIT')); process.once('SIGTERM', onProcessTerm.bind(null, 'SIGTERM')); process.once('SIGINT', onProcessTerm.bind(null, 'SIGINT')); }).catch((err) => { pandora_dollar_1.consoleLogger.error(err); }); } async stop() { await this.applicationHandler.stop(); await this.coreSdk.stop(); } } exports.FrontApplicationLoader = FrontApplicationLoader; //# sourceMappingURL=FrontApplicationLoader.js.map