From 750208f4aea7d20761b5c67cdfffb2897fbf33cd Mon Sep 17 00:00:00 2001 From: Chatnoir Miki Date: Sat, 19 Oct 2024 18:10:20 +0800 Subject: [PATCH] refactor: replace shell commands with filesystem API --- src/commands/new.ts | 9 ++++++--- src/tools/react-native.ts | 34 +++++++++++++--------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/commands/new.ts b/src/commands/new.ts index ff46ad5a6..2d1915917 100644 --- a/src/commands/new.ts +++ b/src/commands/new.ts @@ -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 diff --git a/src/tools/react-native.ts b/src/tools/react-native.ts index 81bbbf817..adfae6e90 100644 --- a/src/tools/react-native.ts +++ b/src/tools/react-native.ts @@ -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 = (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") }