@@ -64,6 +64,7 @@ async function flattenNestedFiles(refDir: string): Promise<void> {
6464
6565 const targetFiles = new Set < string > ( ) ;
6666 const collisions : string [ ] = [ ] ;
67+ const moves : Array < { from : string ; to : string } > = [ ] ;
6768
6869 for ( const file of nestedFiles ) {
6970 const filename = path . basename ( file ) ;
@@ -84,16 +85,25 @@ async function flattenNestedFiles(refDir: string): Promise<void> {
8485 }
8586 targetFiles . add ( targetName ) ;
8687
87- await fs . move ( path . join ( refDir , file ) , path . join ( refDir , targetName ) , {
88- overwrite : false ,
88+ moves . push ( {
89+ from : path . join ( refDir , file ) ,
90+ to : path . join ( refDir , targetName ) ,
8991 } ) ;
9092 }
9193
9294 if ( collisions . length > 0 ) {
9395 log . warn ( `Detected ${ collisions . length } filename collision(s):` , 1 ) ;
9496 collisions . forEach ( ( c ) => log . data ( c , 2 ) ) ;
97+ throw new Error (
98+ `Cannot flatten files: ${ collisions . length } filename collision(s) detected. ` +
99+ `Different source files would overwrite each other.`
100+ ) ;
95101 }
102+
103+ for ( const { from, to } of moves ) {
104+ await fs . move ( from , to , { overwrite : false } ) ;
96105 }
106+ }
97107
98108async function removeEmptyDirectories ( refDir : string ) : Promise < void > {
99109 const dirs = await glob ( "**/" , { cwd : refDir } ) ;
@@ -106,7 +116,7 @@ async function removeEmptyDirectories(refDir: string): Promise<void> {
106116 }
107117 } catch { }
108118 }
109- }
119+ }
110120
111121async function convertMdToMdx ( refDir : string ) : Promise < void > {
112122 const mdFiles = await glob ( "*.md" , { cwd : refDir } ) ;
@@ -123,7 +133,7 @@ async function convertMdToMdx(refDir: string): Promise<void> {
123133 await fs . writeFile ( mdxPath , createFrontmatter ( title ) + content ) ;
124134 await fs . remove ( fullPath ) ;
125135 }
126- }
136+ }
127137
128138async function ensureFrontmatter ( refDir : string ) : Promise < void > {
129139 const mdxFiles = await glob ( `*${ CONSTANTS . MDX_EXTENSION } ` , { cwd : refDir } ) ;
0 commit comments