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
  • Loading branch information
edmundhung committed Oct 1, 2024
1 parent 6009bb4 commit f5c0873
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
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 @@ -246,6 +246,18 @@ describe
const { output } = await runC3(
[project.path, "--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}-test`, keys.enter],
},
{
matcher: /What would you like to start with\?/,
input: {
Expand Down Expand Up @@ -332,7 +344,7 @@ describe
logStream,
);

expect(project.path).toExist();
expect(`${project.path}-test`).toExist();
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`lang JavaScript`);
},
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 f5c0873

Please sign in to comment.