diff --git a/.changeset/early-kangaroos-guess.md b/.changeset/early-kangaroos-guess.md new file mode 100644 index 000000000000..ba9471bad513 --- /dev/null +++ b/.changeset/early-kangaroos-guess.md @@ -0,0 +1,5 @@ +--- +"create-cloudflare": minor +--- + +feat: allow users going back to the project name prompt diff --git a/packages/create-cloudflare/e2e-tests/cli.test.ts b/packages/create-cloudflare/e2e-tests/cli.test.ts index 7edd30085ea5..5030d40bef6b 100644 --- a/packages/create-cloudflare/e2e-tests/cli.test.ts +++ b/packages/create-cloudflare/e2e-tests/cli.test.ts @@ -244,8 +244,20 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())( "Going back and forth between the category, type, framework and lang prompts", async ({ logStream, project }) => { const { output } = await runC3( - [project.path, "--git=false", "--no-deploy"], + ["/invalid-project-name", "--git=false", "--no-deploy"], [ + { + matcher: /What would you like to start with\?/, + input: { + type: "select", + target: "Go back", + }, + }, + { + matcher: + /In which directory do you want to create your application/, + input: [project.path, keys.enter], + }, { matcher: /What would you like to start with\?/, input: { diff --git a/packages/create-cloudflare/src/templates.ts b/packages/create-cloudflare/src/templates.ts index c61c5f77f2cf..14a2f821fe3f 100644 --- a/packages/create-cloudflare/src/templates.ts +++ b/packages/create-cloudflare/src/templates.ts @@ -296,11 +296,15 @@ export const createContext = async ( // Allows the users to go back to the previous step // By moving the cursor up to a certain line and clearing the screen - const goBack = async (from: "type" | "framework" | "lang") => { + const goBack = async (from: "category" | "type" | "framework" | "lang") => { const currentArgs = { ...args }; let linesPrinted = 0; switch (from) { + case "category": + linesPrinted = 6; + args.projectName = undefined; + break; case "type": linesPrinted = 9; args.category = undefined; @@ -341,7 +345,7 @@ export const createContext = async ( type: "text", question: `In which directory do you want to create your application?`, helpText: "also used as application name", - defaultValue: defaultName, + defaultValue: prevArgs?.projectName ?? defaultName, label: "dir", validate: (value) => validateProjectDirectory(String(value) || C3_DEFAULTS.projectName, args), @@ -372,6 +376,7 @@ export const createContext = async ( }, // This is used only if the type is `pre-existing` { label: "Others", value: "others", hidden: true }, + backOption, ]; const category = await processArgument(args, "category", { @@ -382,6 +387,10 @@ export const createContext = async ( defaultValue: prevArgs?.category ?? C3_DEFAULTS.category, }); + if (category === BACK_VALUE) { + return goBack("category"); + } + let template: TemplateConfig; if (category === "web-framework") {