@@ -38,19 +38,30 @@ export default function(options: Options): Rule {
3838 const { buildPaths, testPaths} = await getProjectTsConfigPaths ( tree ) ;
3939 const basePath = process . cwd ( ) ;
4040 const allPaths = [ ...buildPaths , ...testPaths ] ;
41+ // TS and Schematic use paths in POSIX format even on Windows. This is needed as otherwise
42+ // string matching such as `sourceFile.fileName.startsWith(pathToMigrate)` might not work.
43+ const pathToMigrate = normalizePath ( join ( basePath , options . path ) ) ;
44+ let migratedFiles = 0 ;
4145
4246 if ( ! allPaths . length ) {
4347 throw new SchematicsException (
4448 'Could not find any tsconfig file. Cannot run the standalone migration.' ) ;
4549 }
4650
4751 for ( const tsconfigPath of allPaths ) {
48- standaloneMigration ( tree , tsconfigPath , basePath , options ) ;
52+ migratedFiles += standaloneMigration ( tree , tsconfigPath , basePath , pathToMigrate , options ) ;
53+ }
54+
55+ if ( migratedFiles === 0 ) {
56+ throw new SchematicsException ( `Could not find any files to migrate under the path ${
57+ pathToMigrate } . Cannot run the standalone migration.`) ;
4958 }
5059 } ;
5160}
5261
53- function standaloneMigration ( tree : Tree , tsconfigPath : string , basePath : string , options : Options ) {
62+ function standaloneMigration (
63+ tree : Tree , tsconfigPath : string , basePath : string , pathToMigrate : string ,
64+ options : Options ) : number {
5465 if ( options . path . startsWith ( '..' ) ) {
5566 throw new SchematicsException (
5667 'Cannot run standalone migration outside of the current project.' ) ;
@@ -64,11 +75,6 @@ function standaloneMigration(tree: Tree, tsconfigPath: string, basePath: string,
6475 } ) as NgtscProgram ;
6576 const printer = ts . createPrinter ( ) ;
6677
67- // TS and Schematic use paths in POSIX format even on Windows.
68- // This is needed as otherwise string matching such as
69- // `sourceFile.fileName.startsWith(pathToMigrate)` will not work correctly.
70- const pathToMigrate = normalizePath ( join ( basePath , options . path ) ) ;
71-
7278 if ( existsSync ( pathToMigrate ) && ! statSync ( pathToMigrate ) . isDirectory ( ) ) {
7379 throw new SchematicsException ( `Migration path ${
7480 pathToMigrate } has to be a directory. Cannot run the standalone migration.`) ;
@@ -80,8 +86,7 @@ function standaloneMigration(tree: Tree, tsconfigPath: string, basePath: string,
8086 } ) ;
8187
8288 if ( sourceFiles . length === 0 ) {
83- throw new SchematicsException ( `Could not find any files to migrate under the path ${
84- pathToMigrate } . Cannot run the standalone migration.`) ;
89+ return 0 ;
8590 }
8691
8792 let pendingChanges : ChangesByFile ;
@@ -122,4 +127,6 @@ function standaloneMigration(tree: Tree, tsconfigPath: string, basePath: string,
122127 tree . delete ( relative ( basePath , file . fileName ) ) ;
123128 }
124129 }
130+
131+ return sourceFiles . length ;
125132}
0 commit comments