Skip to content

Commit

Permalink
fix(cli): replace shell commands with filesystem API (#2817 by @Aster…
Browse files Browse the repository at this point in the history
…isMono)

[skip ci]
  • Loading branch information
AsterisMono authored Oct 29, 2024
1 parent 97eb1c6 commit fd0a418
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
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")
}

0 comments on commit fd0a418

Please sign in to comment.