@rxap/ts-morph
Version:
Provides utilities for manipulating TypeScript code using the ts-morph library. It offers a fluent API to add, modify, and remove code elements such as classes, decorators, imports, and properties in both Angular and NestJS projects. This package simplifi
54 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoerceNestAppController = CoerceNestAppController;
const coerce_decorator_1 = require("../coerce-decorator");
const coerce_imports_1 = require("../coerce-imports");
const coerce_nest_controller_1 = require("./coerce-nest-controller");
const coerce_nest_operation_1 = require("./coerce-nest-operation");
function CoerceNestAppController(sourceFile, options = {}) {
var _a, _b, _c;
const classDeclaration = (0, coerce_nest_controller_1.CoerceNestController)(sourceFile, Object.assign(Object.assign({}, options), { name: 'app' }));
(0, coerce_decorator_1.CoerceDecorator)(classDeclaration, 'Public', { arguments: [] });
(0, coerce_decorator_1.CoerceDecorator)(classDeclaration, 'ApiExcludeController', { arguments: [] });
(0, coerce_imports_1.CoerceImports)(sourceFile, [
{
moduleSpecifier: '@rxap/nest-utilities',
namedImports: ['Public'],
}, {
moduleSpecifier: '@nestjs/swagger',
namedImports: ['ApiExcludeController'],
},
]);
// region remove the default implementation from the nest generator
(_a = classDeclaration.getMethod('getData')) === null || _a === void 0 ? void 0 : _a.remove();
const [constructorDeclaration] = classDeclaration.getConstructors();
if (constructorDeclaration) {
(_b = constructorDeclaration.getParameter('appService')) === null || _b === void 0 ? void 0 : _b.remove();
if (constructorDeclaration.getParameters().length === 0) {
constructorDeclaration.remove();
}
}
(_c = sourceFile.getImportDeclaration('./app.service')) === null || _c === void 0 ? void 0 : _c.remove();
// endregion
(0, coerce_nest_operation_1.CoerceNestOperation)(sourceFile, {
operationName: 'name',
returnType: 'string',
statements: ['return environment.app;'],
});
(0, coerce_nest_operation_1.CoerceNestOperation)(sourceFile, {
operationName: 'environment',
returnType: 'Environment',
statements: ['return environment;'],
path: 'info',
});
(0, coerce_imports_1.CoerceImports)(sourceFile, [
{
moduleSpecifier: '../environments/environment',
namedImports: ['environment'],
}, {
moduleSpecifier: '@rxap/nest-utilities',
namedImports: ['Environment'],
},
]);
}
//# sourceMappingURL=coerce-nest-app-controller.js.map