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

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

Merged
merged 3 commits into from
Oct 17, 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
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
Loading