@glandjs/core
Version:
Glands is a web framework for Node.js (@core)
48 lines (47 loc) • 2.06 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationInitial = void 0;
const injector_1 = require("../injector");
const application_binder_1 = require("./application-binder");
const application_lifecycle_1 = require("./application-lifecycle");
class ApplicationInitial {
constructor(broker, logger, mode) {
this.broker = broker;
this.logger = logger;
this.mode = mode;
this.dependenciesScanner = new injector_1.DependenciesScanner(this.getLogger());
}
getLogger() {
return this.mode ? this.logger : undefined;
}
async initialize(root) {
const logger = this.logger.child('Initial');
try {
logger.info('Scanning module dependencies');
await this.dependenciesScanner.scan(root);
logger.info('Initializing dependency injector');
const explorer = new injector_1.Explorer(this.dependenciesScanner.modules, this.getLogger());
this.lifecycle = new application_lifecycle_1.ApplicationLifecycle(this.dependenciesScanner.modules, this.getLogger());
this.logger.info('Running module initialization hooks');
await this.lifecycle.init();
logger.info('Binding application components');
const appBinder = new application_binder_1.ApplicationBinder(explorer, this.broker, this.getLogger());
appBinder.bind();
this.logger.info('Running channel initialization hooks');
await this.lifecycle.initChannels();
this.logger.info('Bootstrapping application');
await this.lifecycle.bootstrap();
this.logger.info('Application initialized successfully');
}
catch (error) {
logger.error(`Application initialization failed: ${error.message}`);
throw error;
}
}
async shutdown(signal) {
if (this.lifecycle) {
await this.lifecycle.shutdown(signal);
}
}
}
exports.ApplicationInitial = ApplicationInitial;