@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
25 lines • 960 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrganizeImports = OrganizeImports;
const ts_morph_1 = require("@rxap/ts-morph");
function OrganizeImports() {
return (tree) => {
const project = (0, ts_morph_1.CreateProject)();
console.debug('organize imports for ts files');
for (const action of tree.actions.slice()) {
switch (action.kind) {
case 'c':
case 'o':
if (action.path.match(/\.ts$/)) {
project.createSourceFile(action.path, action.content.toString('utf-8'), { overwrite: true });
}
break;
}
}
project.getSourceFiles().forEach(sourceFile => {
sourceFile.organizeImports();
tree.overwrite(sourceFile.getFilePath(), sourceFile.getFullText());
});
};
}
//# sourceMappingURL=organize-imports.js.map