2025-01-28 08:19:46 -06:00
#!/usr/bin/env node
/ * *
* This script is used to reset the project to a blank state .
* It moves the / app , / c o m p o n e n t s , / h o o k s , / s c r i p t s , a n d / c o n s t a n t s d i r e c t o r i e s t o / a p p - e x a m p l e a n d c r e a t e s a n e w / a p p d i r e c t o r y w i t h a n i n d e x . t s x a n d _ l a y o u t . t s x f i l e .
* You can remove the ` reset-project ` script from package . json and safely delete this file after running it .
* /
2025-01-28 08:45:02 -06:00
const fs = require ( 'fs' ) ;
const path = require ( 'path' ) ;
2025-01-28 08:19:46 -06:00
const root = process . cwd ( ) ;
2025-01-28 08:45:02 -06:00
const oldDirs = [ 'app' , 'components' , 'hooks' , 'constants' , 'scripts' ] ;
const newDir = 'app-example' ;
const newAppDir = 'app' ;
2025-01-28 08:19:46 -06:00
const newDirPath = path . join ( root , newDir ) ;
const indexContent = ` import { Text, View } from "react-native";
export default function Index ( ) {
return (
< View
style = { {
flex : 1 ,
justifyContent : "center" ,
alignItems : "center" ,
} }
>
< Text > Edit app / index . tsx to edit this screen . < / T e x t >
< / V i e w >
) ;
}
` ;
const layoutContent = ` import { Stack } from "expo-router";
export default function RootLayout ( ) {
return < Stack / > ;
}
` ;
const moveDirectories = async ( ) => {
try {
// Create the app-example directory
await fs . promises . mkdir ( newDirPath , { recursive : true } ) ;
console . log ( ` 📁 / ${ newDir } directory created. ` ) ;
// Move old directories to new app-example directory
for ( const dir of oldDirs ) {
const oldDirPath = path . join ( root , dir ) ;
const newDirPath = path . join ( root , newDir , dir ) ;
if ( fs . existsSync ( oldDirPath ) ) {
await fs . promises . rename ( oldDirPath , newDirPath ) ;
console . log ( ` ➡️ / ${ dir } moved to / ${ newDir } / ${ dir } . ` ) ;
} else {
console . log ( ` ➡️ / ${ dir } does not exist, skipping. ` ) ;
}
}
// Create new /app directory
const newAppDirPath = path . join ( root , newAppDir ) ;
await fs . promises . mkdir ( newAppDirPath , { recursive : true } ) ;
2025-01-28 08:45:02 -06:00
console . log ( '\n📁 New /app directory created.' ) ;
2025-01-28 08:19:46 -06:00
// Create index.tsx
2025-01-28 08:45:02 -06:00
const indexPath = path . join ( newAppDirPath , 'index.tsx' ) ;
2025-01-28 08:19:46 -06:00
await fs . promises . writeFile ( indexPath , indexContent ) ;
2025-01-28 08:45:02 -06:00
console . log ( '📄 app/index.tsx created.' ) ;
2025-01-28 08:19:46 -06:00
// Create _layout.tsx
2025-01-28 08:45:02 -06:00
const layoutPath = path . join ( newAppDirPath , '_layout.tsx' ) ;
2025-01-28 08:19:46 -06:00
await fs . promises . writeFile ( layoutPath , layoutContent ) ;
2025-01-28 08:45:02 -06:00
console . log ( '📄 app/_layout.tsx created.' ) ;
2025-01-28 08:19:46 -06:00
2025-01-28 08:45:02 -06:00
console . log ( '\n✅ Project reset complete. Next steps:' ) ;
2025-01-28 08:19:46 -06:00
console . log (
2025-01-28 08:45:02 -06:00
"1. Run `npx expo start` to start a development server.\n2. Edit app/index.tsx to edit the main screen.\n3. Delete the /app-example directory when you're done referencing it." ,
2025-01-28 08:19:46 -06:00
) ;
} catch ( error ) {
console . error ( ` Error during script execution: ${ error } ` ) ;
}
} ;
moveDirectories ( ) ;