UNPKG

@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

35 lines 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddDir = AddDir; const path_1 = require("path"); /** * Adds all files recursively from a specify DirEntry to the project. * @param dir A schematic DirEntry instance * @param project A ts-morph Project instance * @param parentPath The base dir for the sourceFiles in the ts-morph Project * @param filter A filter function base on the pathFragment and dirEntry */ function AddDir(dir, project, parentPath = '', filter = pathFragment => !!pathFragment.match(/\.ts$/)) { for (const pathFragment of dir.subfiles.filter(pf => filter(pf, dir))) { const fileEntry = dir.file(pathFragment); if (fileEntry) { const filePath = (0, path_1.join)(parentPath, pathFragment); if (!project.getSourceFile(filePath)) { project.createSourceFile(filePath, fileEntry.content.toString('utf-8')); } } else { throw new Error('The path fragment does not point to a file entry'); } } for (const pathFragment of dir.subdirs) { const dirEntry = dir.dir(pathFragment); if (dirEntry) { AddDir(dirEntry, project, (0, path_1.join)(parentPath, pathFragment), filter); } else { throw new Error('The path fragment does not point to a dir entry'); } } } //# sourceMappingURL=add-dir.js.map