Skip to content

Commit

Permalink
feat(create-cloudflare): allows user going back to the project name p…
Browse files Browse the repository at this point in the history
…rompt (#6846)

* feat(create-cloudflare): allows user going back to the project name prompt

* add changeset

* fixup! add changeset
  • Loading branch information
edmundhung authored Oct 17, 2024
1 parent 284c962 commit ae4bfea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-kangaroos-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": minor
---

feat: allow users going back to the project name prompt
14 changes: 13 additions & 1 deletion packages/create-cloudflare/e2e-tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
13 changes: 11 additions & 2 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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", {
Expand All @@ -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") {
Expand Down

0 comments on commit ae4bfea

Please sign in to comment.