(options: Options)
| 22 | } |
| 23 | |
| 24 | export function migrate(options: Options): Rule { |
| 25 | return async (tree: Tree, context: SchematicContext) => { |
| 26 | const basePath = process.cwd(); |
| 27 | let pathToMigrate: string | undefined; |
| 28 | if (options.path) { |
| 29 | if (options.path.startsWith('..')) { |
| 30 | throw new SchematicsException( |
| 31 | 'Cannot run inject migration outside of the current project.', |
| 32 | ); |
| 33 | } |
| 34 | pathToMigrate = normalizePath(join(basePath, options.path)); |
| 35 | } |
| 36 | |
| 37 | const {buildPaths, testPaths} = await getProjectTsConfigPaths(tree); |
| 38 | const allPaths = [...buildPaths, ...testPaths]; |
| 39 | |
| 40 | if (!allPaths.length) { |
| 41 | context.logger.warn('Could not find any tsconfig file. Cannot run the inject migration.'); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | let sourceFilesCount = 0; |
| 46 | |
| 47 | for (const tsconfigPath of allPaths) { |
| 48 | const program = createMigrationProgram(tree, tsconfigPath, basePath); |
| 49 | const sourceFiles = program |
| 50 | .getSourceFiles() |
| 51 | .filter( |
| 52 | (sourceFile) => |
| 53 | (pathToMigrate ? sourceFile.fileName.startsWith(pathToMigrate) : true) && |
| 54 | canMigrateFile(basePath, sourceFile, program), |
| 55 | ); |
| 56 | |
| 57 | sourceFilesCount += runInjectMigration(tree, sourceFiles, basePath, options); |
| 58 | } |
| 59 | |
| 60 | if (sourceFilesCount === 0) { |
| 61 | context.logger.warn('Inject migration did not find any files to migrate'); |
| 62 | } |
| 63 | }; |
| 64 | } |
| 65 | |
| 66 | function runInjectMigration( |
| 67 | tree: Tree, |
nothing calls this directly
no test coverage detected