UNPKG

pandora

Version:

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

119 lines 5.05 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const ServiceRepresentationChainModifier_1 = require("./ServiceRepresentationChainModifier"); const ProcessRepresentationChainModifier_1 = require("./ProcessRepresentationChainModifier"); const pandora_dollar_1 = require("pandora-dollar"); const ServiceUtils_1 = require("../service/ServiceUtils"); /** * Class ProcfileReconcilerAccessor * A easy way to access ProcfileReconciler */ class ProcfileReconcilerAccessor { constructor(procfileReconciler) { this.procfileReconciler = null; this.clusterCount = 0; this.procfileReconciler = procfileReconciler; } get dev() { return process.env.PANDORA_DEV === 'true'; } get appName() { return this.procfileReconciler.appRepresentation.appName; } get appDir() { return this.procfileReconciler.appRepresentation.appDir; } defaultServiceCategory(name) { this.procfileReconciler.setDefaultServiceCategory(name); } /** * Inject environment class * @param {Entry} entry */ environment(entry) { this.procfileReconciler.injectEnvironment(entry); } /** * define process * @param processName * @return {ProcessRepresentationChainModifier} */ process(processName) { const savedRepresentation = this.procfileReconciler.getProcessByName(processName); if (this.procfileReconciler.getProcessByName(processName)) { return new ProcessRepresentationChainModifier_1.ProcessRepresentationChainModifier(savedRepresentation, this.procfileReconciler); } const representation = this.procfileReconciler.defineProcess({ processName }); return new ProcessRepresentationChainModifier_1.ProcessRepresentationChainModifier(representation, this.procfileReconciler); } /** * Define fork a process * @param processName * @param entryFile * @return {ProcessRepresentationChainModifier} */ fork(processName, entryFile) { const savedRepresentation = this.procfileReconciler.getProcessByName(processName); if (savedRepresentation) { return new ProcessRepresentationChainModifier_1.ProcessRepresentationChainModifier(savedRepresentation, this.procfileReconciler); } const representation = this.procfileReconciler.defineProcess({ entryFile, processName, mode: 'fork' }); return new ProcessRepresentationChainModifier_1.ProcessRepresentationChainModifier(representation, this.procfileReconciler); } /** * Inject service class * @param serviceName * @param serviceEntry * @return {ServiceRepresentationChainModifier} */ service(serviceName, serviceEntry) { ServiceUtils_1.ServiceUtils.checkName(serviceName); const savedRepresentation = this.procfileReconciler.getServiceByName(serviceName); if (savedRepresentation && serviceEntry) { throw new Error(`Service already exist! Use pandora.service('${serviceName}').entry('a new place') to change the entry.`); } if (savedRepresentation) { return new ServiceRepresentationChainModifier_1.ServiceRepresentationChainModifier(savedRepresentation, this.procfileReconciler); } const representation = this.procfileReconciler.injectService({ serviceName, serviceEntry }); return new ServiceRepresentationChainModifier_1.ServiceRepresentationChainModifier(representation, this.procfileReconciler); } /** * An alias to service() * @param path * @return {ServiceRepresentationChainModifier} */ cluster(path) { const baseDir = this.procfileReconciler.procfileBasePath; class ClusterService { start() { return __awaiter(this, void 0, void 0, function* () { if (baseDir) { pandora_dollar_1.makeRequire(baseDir)(path); } else { require(path); } }); } } ClusterService.dependencies = ['all']; return this.service('cluster' + this.clusterCount++, ClusterService); } } exports.ProcfileReconcilerAccessor = ProcfileReconcilerAccessor; //# sourceMappingURL=ProcfileReconcilerAccessor.js.map