UNPKG

@nestjs-mod/pm2

Version:

Production process manager for Node.JS applications with a built-in load balancer for NestJS-mod (Generator ecosystem.config.json for https://www.npmjs.com/package/pm2)

45 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Pm2EcosystemConfigFileService = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const fs_1 = require("fs"); const path_1 = require("path"); const pm2_configuration_1 = require("./pm2.configuration"); let Pm2EcosystemConfigFileService = class Pm2EcosystemConfigFileService { constructor(pm2Configuration) { this.pm2Configuration = pm2Configuration; } getEcosystemConfigFilePath() { return this.pm2Configuration.ecosystemConfigFile; } read() { try { // eslint-disable-next-line @typescript-eslint/no-var-requires const ecosystemConfigJsModule = JSON.parse((0, fs_1.readFileSync)(this.getEcosystemConfigFilePath()).toString()); return ecosystemConfigJsModule; } catch (err) { return { apps: [] }; } } write({ apps }) { if (!this.getEcosystemConfigFilePath()) { return; } const content = JSON.stringify({ apps }, null, 2); const fileDir = (0, path_1.dirname)(this.getEcosystemConfigFilePath()); if (fileDir) { if (!(0, fs_1.existsSync)(fileDir)) { (0, fs_1.mkdirSync)(fileDir, { recursive: true }); } (0, fs_1.writeFileSync)(this.getEcosystemConfigFilePath(), content); } } }; exports.Pm2EcosystemConfigFileService = Pm2EcosystemConfigFileService; exports.Pm2EcosystemConfigFileService = Pm2EcosystemConfigFileService = tslib_1.__decorate([ (0, common_1.Injectable)(), tslib_1.__metadata("design:paramtypes", [pm2_configuration_1.Pm2Configuration]) ], Pm2EcosystemConfigFileService); //# sourceMappingURL=pm2-ecosystem-config-file.service.js.map