UNPKG

@lakutata/core

Version:

Lakutata Framework Core

46 lines 1.99 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getApp = exports.createApp = void 0; const moment_timezone_1 = __importDefault(require("moment-timezone")); require('events').captureRejections = true; const Application_1 = require("./Application"); const FatalException_1 = require("./exceptions/FatalException"); const Container_1 = require("./base/Container"); const MetadataKeys_1 = require("./constants/MetadataKeys"); if (!Reflect.getMetadata(MetadataKeys_1.CORE_CONTAINER_ID, process)) Reflect.defineMetadata(MetadataKeys_1.CORE_CONTAINER_ID, new Container_1.Container(), process); async function createApp(config) { try { const coreContainer = Reflect.getMetadata(MetadataKeys_1.CORE_CONTAINER_ID, process); coreContainer.bindModule(Application_1.Application, config); process.title = config.id; process.env.appId = config.id; process.env.appName = config.name; process.env.TZ = config.timezone ? config.timezone : moment_timezone_1.default.tz.guess(); await coreContainer.initialize(); return coreContainer.getModule(Application_1.Application); } catch (e) { const fatalException = new FatalException_1.FatalException(e.message); const createAppErrorStack = e.stack; if (createAppErrorStack) { fatalException.stack = createAppErrorStack; } throw fatalException; } } exports.createApp = createApp; function getApp() { try { const coreContainer = Reflect.getMetadata(MetadataKeys_1.CORE_CONTAINER_ID, process); return coreContainer.getModule(Application_1.Application); } catch (e) { throw new FatalException_1.FatalException('Application is not launched'); } } exports.getApp = getApp; //# sourceMappingURL=ApplicationManagement.js.map