@@ -3,6 +3,7 @@ import fs from "node:fs";
33import path from "node:path" ;
44
55const RenamedFiles : { [ key : string ] : string } = { } ;
6+ const PageRoutes : { [ key : string ] : string } = { } ;
67
78export function randomizeName ( filePath : string ) : string {
89 const extname = path . extname ( filePath ) ;
@@ -46,9 +47,16 @@ export function RandomizeNames() {
4647 const newPath = path . resolve ( path . dirname ( file ) , newName ) ;
4748 RenamedFiles [ oldPath ] = newPath ;
4849 fs . renameSync ( oldPath , newPath ) ;
50+
51+ if ( file . startsWith ( path . join ( process . cwd ( ) , "src" , "pages" ) ) ) {
52+ const oldRoute = oldPath . replace ( process . cwd ( ) + "/src/pages" , "" ) . replace ( / \\ / g, "/" ) ;
53+ const newRoute = newPath . replace ( process . cwd ( ) + "/src/pages" , "" ) . replace ( / \\ / g, "/" ) ;
54+ PageRoutes [ oldRoute ] = newRoute ;
55+ }
4956 }
5057
5158 updateImports ( ) ;
59+ updatePageRoutes ( ) ;
5260}
5361
5462export function updateImports ( ) {
@@ -92,6 +100,26 @@ export function updateImports() {
92100 }
93101}
94102
103+ export function updatePageRoutes ( ) {
104+ const allFiles = [
105+ ...findFiles ( path . join ( process . cwd ( ) , "src" ) , / \. a s t r o $ / ) ,
106+ ...findFiles ( path . join ( process . cwd ( ) , "src" ) , / \. t s $ / ) ,
107+ ] ;
108+
109+ for ( const file of allFiles ) {
110+ let fileContent = fs . readFileSync ( file , "utf-8" ) ;
111+
112+ for ( const [ oldRoute , newRoute ] of Object . entries ( PageRoutes ) ) {
113+ fileContent = fileContent . replace (
114+ new RegExp ( `['"]${ oldRoute . replace ( ".astro" , "" ) } ['"]` , "g" ) ,
115+ `'${ newRoute . replace ( ".astro" , "" ) } '`
116+ ) ;
117+ }
118+
119+ fs . writeFileSync ( file , fileContent , "utf-8" ) ;
120+ }
121+ }
122+
95123export function renameEDirectory ( ) {
96124 const eDirPath = path . join ( process . cwd ( ) , "src" , "pages" , "e" ) ;
97125 if ( fs . existsSync ( eDirPath ) ) {
@@ -105,7 +133,7 @@ export async function Revert() {
105133 try {
106134 console . log ( "Reverting Changes." ) ;
107135 execSync ( "git restore src/" , { cwd : process . cwd ( ) , stdio : "inherit" } ) ;
108- execSync ( "git clean -fdx src/" , { cwd : process . cwd ( ) , stdio : "inherit" } ) ;
136+ execSync ( "git clean -fdx src/" , { cwd : process . cwd ( ) , stdio : "inherit" } ) ;
109137
110138 await new Promise ( ( resolve ) => setTimeout ( resolve , 2000 ) ) ;
111139 console . log ( "Revert completed." ) ;
0 commit comments