MCPcopy Create free account
hub / github.com/expo/examples / moveDirectories

Function moveDirectories

with-react-navigation/src/scripts/reset-project.js:65–122  ·  view source on GitHub ↗
(userInput)

Source from the content-addressed store, hash-verified

63});
64
65const moveDirectories = async (userInput) => {
66 try {
67 if (userInput === 'y') {
68 // Create the src-example directory
69 await fs.promises.mkdir(exampleDirPath, { recursive: true });
70 console.log(`📁 /${exampleDir} directory created.`);
71 }
72
73 // Move old directories from src to src-example or delete them
74 for (const dir of oldDirs) {
75 const oldDirPath = path.join(srcPath, dir);
76 if (fs.existsSync(oldDirPath)) {
77 if (userInput === 'y') {
78 const newDirPath = path.join(exampleDirPath, dir);
79 await fs.promises.rename(oldDirPath, newDirPath);
80 console.log(`➡️ /src/${dir} moved to /${exampleDir}/${dir}.`);
81 } else {
82 await fs.promises.rm(oldDirPath, { recursive: true, force: true });
83 console.log(`❌ /src/${dir} deleted.`);
84 }
85 } else {
86 console.log(`➡️ /src/${dir} does not exist, skipping.`);
87 }
88 }
89
90 // Create new navigation directory structure
91 const navigationPath = path.join(srcPath, 'navigation');
92 const screensPath = path.join(navigationPath, 'screens');
93 await fs.promises.mkdir(screensPath, { recursive: true });
94 console.log('\n📁 New /src/navigation directory structure created.');
95
96 // Create Home.tsx screen
97 const homePath = path.join(screensPath, 'Home.tsx');
98 await fs.promises.writeFile(homePath, homeScreenContent);
99 console.log('📄 src/navigation/screens/Home.tsx created.');
100
101 // Create navigation index.tsx
102 const navIndexPath = path.join(navigationPath, 'index.tsx');
103 await fs.promises.writeFile(navIndexPath, navigationContent);
104 console.log('📄 src/navigation/index.tsx created.');
105
106 // Update App.tsx
107 const appPath = path.join(srcPath, 'App.tsx');
108 await fs.promises.writeFile(appPath, appContent);
109 console.log('📄 src/App.tsx updated.');
110
111 console.log('\n✅ Project reset complete. Next steps:');
112 console.log(
113 `1. Run \`npx expo start\` to start a development server.\n2. Edit src/navigation/screens/Home.tsx to edit the main screen.${
114 userInput === 'y'
115 ? `\n3. Delete the /${exampleDir} directory when you're done referencing it.`
116 : ''
117 }`
118 );
119 } catch (error) {
120 console.error(`❌ Error during script execution: ${error.message}`);
121 }
122};

Callers 1

reset-project.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected