@tsdi/platform-server-boot
Version:
boot application on node server, AOP Ioc container, via typescript decorator
155 lines (135 loc) • 5.35 kB
JavaScript
;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var tslib = _interopDefault(require('tslib'));
var ioc = _interopDefault(require('@tsdi/ioc'));
var boot = _interopDefault(require('@tsdi/boot'));
var platformServer = _interopDefault(require('@tsdi/platform-server'));
var path = _interopDefault(require('path'));
function unwrapExports (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var BootstrapModule = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServerBootstrapModule = exports.ConfigureFileLoader = void 0;
/**
* 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 || platformServer.runMainPath();
}
ConfigureFileLoader.prototype.load = function (uri) {
return tslib.__awaiter(this, void 0, void 0, function () {
var fs, cfgmodeles_1, cfgpath_1;
return tslib.__generator(this, function (_a) {
fs = platformServer.syncRequire('fs');
if (uri) {
if (fs.existsSync(uri)) {
return [2 /*return*/, platformServer.syncRequire(uri)];
}
else if (fs.existsSync(path.join(this.baseURL, uri))) {
return [2 /*return*/, platformServer.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 = platformServer.syncRequire(cfgpath_1 + ext);
}
return !!cfgmodeles_1;
});
return [2 /*return*/, cfgmodeles_1];
}
});
});
};
ConfigureFileLoader.ρAnn = function () {
return { "name": "ConfigureFileLoader", "params": { "constructor": ["baseURL", "container"], "load": ["uri"] } };
};
ConfigureFileLoader = tslib.__decorate([
ioc.Injectable(boot.ConfigureLoaderToken),
tslib.__metadata("design:paramtypes", [String, Object])
], ConfigureFileLoader);
return ConfigureFileLoader;
}());
exports.ConfigureFileLoader = ConfigureFileLoader;
var ServerApplicationExit = /** @class */ (function (_super) {
tslib.__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);
};
ServerApplicationExit.ρAnn = function () {
return { "name": "ServerApplicationExit" };
};
return ServerApplicationExit;
}(boot.ApplicationExit));
/**
* server boot module
*
* @export
* @class ServerBootstrapModule
*/
var ServerBootstrapModule = /** @class */ (function () {
function ServerBootstrapModule() {
}
ServerBootstrapModule.ρAnn = function () {
return { "name": "ServerBootstrapModule", "params": {} };
};
ServerBootstrapModule = tslib.__decorate([
boot.DIModule({
regIn: 'root',
imports: [
platformServer.ServerModule
],
providers: [
ConfigureFileLoader,
{ provide: boot.ProcessRunRootToken, useValue: platformServer.runMainPath() },
{ provide: boot.ApplicationExit, useValue: new ServerApplicationExit() }
]
})
], ServerBootstrapModule);
return ServerBootstrapModule;
}());
exports.ServerBootstrapModule = ServerBootstrapModule;
});
unwrapExports(BootstrapModule);
var BootstrapModule_1 = BootstrapModule.ServerBootstrapModule;
var BootstrapModule_2 = BootstrapModule.ConfigureFileLoader;
var src = createCommonjsModule(function (module, exports) {
Object.defineProperty(exports, "__esModule", { value: true });
tslib.__exportStar(BootstrapModule, exports);
});
var index = unwrapExports(src);
module.exports = index;
//# sourceMappingURL=platform-server-boot.js.map