rucken
Version:
Console tools and scripts for nx and not only that I (EndyKaufman) use to automate the workflow and speed up the development process
59 lines (58 loc) • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsoleModule = void 0;
const tslib_1 = require("tslib");
/**
* @module ConsoleModule
*/
const common_1 = require("@nestjs/common");
const constants_1 = require("./constants");
const scanner_1 = require("./scanner");
const service_1 = require("./service");
const cliProvider = {
provide: constants_1.CLI_SERVICE_TOKEN,
useFactory: () => service_1.ConsoleService.createCli(),
};
let ConsoleModule = class ConsoleModule {
constructor(service) {
this.service = service;
this.scanner = new scanner_1.ConsoleScanner();
}
scan(app, includedModules) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const scanResponse = yield this.scanner.scan(app, includedModules);
const cli = this.service.getRootCli();
scanResponse.forEach(({ methods, instance, metadata }) => {
let parent = cli;
let subCli = this.service.getCli(metadata.command);
if (subCli !== undefined) {
parent = subCli;
}
else {
const commandNames = metadata.command.split('.');
if (commandNames.length > 1) {
commandNames.pop();
subCli = this.service.getCli(commandNames.join('.'));
}
if (subCli === undefined) {
parent = this.service.createGroupCommand(metadata, cli);
}
else {
parent = this.service.createGroupCommand(metadata, subCli);
}
}
for (const method of methods) {
this.service.createCommand(method.metadata, { instance, methodName: method.name }, parent);
}
});
});
}
};
ConsoleModule = tslib_1.__decorate([
(0, common_1.Module)({
providers: [cliProvider, service_1.ConsoleService],
exports: [service_1.ConsoleService],
}),
tslib_1.__metadata("design:paramtypes", [service_1.ConsoleService])
], ConsoleModule);
exports.ConsoleModule = ConsoleModule;