UNPKG

@tsdi/platform-server-boot

Version:

boot application on node server, AOP Ioc container, via typescript decorator

120 lines (118 loc) 4.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServerBootstrapModule = exports.ConfigureFileLoader = void 0; var tslib_1 = require("tslib"); var ioc_1 = require("@tsdi/ioc"); var boot_1 = require("@tsdi/boot"); var platform_server_1 = require("@tsdi/platform-server"); var path = require("path"); /** * configure file loader. * * @export * @class ConfigureFileLoader * @implements {IConfigureLoader<Configure>} */ var ConfigureFileLoader = /** @class */ (function () { function ConfigureFileLoader(baseURL, container) { this.baseURL = baseURL; this.container = container; this.baseURL = this.baseURL || platform_server_1.runMainPath(); } ConfigureFileLoader.prototype.load = function (uri) { return tslib_1.__awaiter(this, void 0, void 0, function () { var fs, cfgmodeles_1, cfgpath_1; return tslib_1.__generator(this, function (_a) { fs = platform_server_1.syncRequire('fs'); if (uri) { if (fs.existsSync(uri)) { return [2 /*return*/, platform_server_1.syncRequire(uri)]; } else if (fs.existsSync(path.join(this.baseURL, uri))) { return [2 /*return*/, platform_server_1.syncRequire(path.join(this.baseURL, uri))]; } else { console.log("config file: " + uri + " not exists."); return [2 /*return*/, null]; } } else { cfgpath_1 = path.join(this.baseURL, './config'); ['.js', '.ts', '.json'].some(function (ext) { if (fs.existsSync(cfgpath_1 + ext)) { cfgmodeles_1 = platform_server_1.syncRequire(cfgpath_1 + ext); } return !!cfgmodeles_1; }); return [2 /*return*/, cfgmodeles_1]; } return [2 /*return*/]; }); }); }; ConfigureFileLoaderAnn = function () { return { "name": "ConfigureFileLoader", "params": { "constructor": ["baseURL", "container"], "load": ["uri"] } }; }; ConfigureFileLoader = tslib_1.__decorate([ ioc_1.Injectable(boot_1.ConfigureLoaderToken), tslib_1.__metadata("design:paramtypes", [String, Object]) ], ConfigureFileLoader); return ConfigureFileLoader; }()); exports.ConfigureFileLoader = ConfigureFileLoader; var ServerApplicationExit = /** @class */ (function (_super) { tslib_1.__extends(ServerApplicationExit, _super); function ServerApplicationExit() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.enable = true; return _this; } ServerApplicationExit.prototype.exit = function (context, err) { var _a; var logger = (_a = context.getLogManager()) === null || _a === void 0 ? void 0 : _a.getLogger(); if (err) { logger ? logger.error(err) : console.error(err); } context.destroy(); if (logger) { logger.log('SIGINT: app destoryed.'); } else { console.log('SIGINT: app destoryed.'); } process.exit(err ? 1 : 0); }; ServerApplicationExitAnn = function () { return { "name": "ServerApplicationExit" }; }; return ServerApplicationExit; }(boot_1.ApplicationExit)); /** * server boot module * * @export * @class ServerBootstrapModule */ var ServerBootstrapModule = /** @class */ (function () { function ServerBootstrapModule() { } ServerBootstrapModuleAnn = function () { return { "name": "ServerBootstrapModule", "params": {} }; }; ServerBootstrapModule = tslib_1.__decorate([ boot_1.DIModule({ regIn: 'root', imports: [ platform_server_1.ServerModule ], providers: [ ConfigureFileLoader, { provide: boot_1.ProcessRunRootToken, useValue: platform_server_1.runMainPath() }, { provide: boot_1.ApplicationExit, useValue: new ServerApplicationExit() } ] }) ], ServerBootstrapModule); return ServerBootstrapModule; }()); exports.ServerBootstrapModule = ServerBootstrapModule; //# sourceMappingURL=sourcemaps/BootstrapModule.js.map