@rxap/schematics-ts-morph
Version:
This package provides utilities for manipulating TypeScript code using ts-morph, particularly for Angular and NestJS projects. It offers functions to add, coerce, and modify code elements like classes, methods, decorators, and imports. The package also in
31 lines • 1.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoerceInterface = CoerceInterface;
exports.CoerceInterfaceRule = CoerceInterfaceRule;
const ts_morph_1 = require("@rxap/ts-morph");
const utilities_1 = require("@rxap/utilities");
function CoerceInterface(sourceFile, interfaceName, structure = {}) {
let interfaceDeclaration = sourceFile.getInterface(interfaceName);
if (!interfaceDeclaration) {
interfaceDeclaration = sourceFile.addInterface(Object.assign(Object.assign({}, structure), { name: interfaceName }));
}
return interfaceDeclaration;
}
function CoerceInterfaceRule(options, tsMorphTransForm) {
const { tsMorphTransform = utilities_1.noop, project, feature, shared, directory, structure = { isExported: true }, propertyList, } = options;
let { name } = options;
name = (0, utilities_1.classify)(name);
return tsMorphTransForm({
project,
feature,
shared,
directory,
}, (project, [sourceFile]) => {
if (propertyList) {
structure.properties = propertyList.map(p => (0, ts_morph_1.NormalizeDataPropertyToPropertySignatureStructure)(p, sourceFile));
}
const interfaceDeclaration = CoerceInterface(sourceFile, name, structure);
tsMorphTransform(project, sourceFile, interfaceDeclaration);
}, [(0, utilities_1.dasherize)(name) + '.ts?']);
}
//# sourceMappingURL=coerce-interface.js.map