Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace shell commands with filesystem API in project creation #2817

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,19 @@ module.exports = {
* 4. Create a screen template that makes sense for Expo Router
* 5. Clean up - move ErrorBoundary to proper spot and remove unused files
*/
await system.run(log(`mv app/* src/`))
filesystem
.cwd(targetPath)
.find("app")
.forEach((file) => filesystem.cwd(targetPath).move(file, file.replace("app", "src")))
updateExpoRouterSrcDir(toolbox)
refactorExpoRouterReactotronCmds(toolbox)
createExpoRouterScreenTemplate(toolbox)
await cleanupExpoRouterConversion(toolbox)
cleanupExpoRouterConversion(toolbox, targetPath)

stopSpinner(expoRouterMsg, "🧭")
} else {
// remove src/ dir since not using expo-router
await system.run(log(`rm -rf src`))
filesystem.cwd(targetPath).remove("src")
}
// #endregion

Expand Down
34 changes: 13 additions & 21 deletions src/tools/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,27 +327,19 @@ export function updateExpoRouterSrcDir(toolbox: GluegunToolbox) {
})
}

export async function cleanupExpoRouterConversion(toolbox: GluegunToolbox) {
const { system, parameters, print } = toolbox

// debug?
const debug = boolFlag(parameters.options.debug)
const log = <T = unknown>(m: T): T => {
debug && print.info(` ${m}`)
return m
}
export function cleanupExpoRouterConversion(toolbox: GluegunToolbox, targetPath: string) {
const { filesystem } = toolbox

await system.run(
log(`
\\rm src/app.tsx
mkdir src/components/ErrorBoundary
mv src/screens/ErrorScreen/* src/components/ErrorBoundary
rm App.tsx
rm ignite/templates/screen/NAMEScreen.tsx.ejs
rm -rf ignite/templates/navigator
rm -rf src/screens
rm -rf src/navigators
rm -rf app
`),
const workingDir = filesystem.cwd(targetPath)
workingDir.cwd("src").remove("app.tsx")
workingDir.move(
workingDir.path("src", "screens", "ErrorScreen"),
workingDir.path("src", "components", "ErrorBoundary"),
)
workingDir.remove("App.tsx")
workingDir.remove(workingDir.path("ignite", "templates", "screen", "NAMEScreen.tsx.ejs"))
workingDir.remove(workingDir.path("ignite", "templates", "navigator"))
workingDir.remove(workingDir.path("src", "screens"))
workingDir.remove(workingDir.path("src", "navigators"))
workingDir.remove("app")
}