Skip to content

Commit 3f41730

Browse files
remove Application Starter option in C3 experimental menu (#8395)
* fix: remove categories in C3 that have no templates The `Application Starter` category doesn't contain any entries in experimental mode so we shouldn't show it. This change updates C3 to automatically exclude categories that have no templates. * remove incorrect caregory and fix e2e snapshots * update another snapshot * skip arrows + enter e2e test in experimental mode * remove qwik from snapshot * update allowed values in snapshot * update test * update missing starter -> example * update missing Starter to example --------- Co-authored-by: Pete Bacon Darwin <[email protected]>
1 parent 25eaf3b commit 3f41730

File tree

11 files changed

+280
-87
lines changed

11 files changed

+280
-87
lines changed

.changeset/metal-shoes-cut.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
Remove categories in C3 that have no templates
6+
7+
The `Application Starter` category doesn't contain any entries in experimental mode so we shouldn't show it.
8+
9+
This change updates C3 to automatically exclude categories that have no templates.

packages/create-cloudflare/e2e-tests/cli.test.ts

Lines changed: 181 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import {
1111
runC3,
1212
test,
1313
} from "./helpers";
14-
import type { Suite } from "vitest";
1514

1615
const experimental = process.env.E2E_EXPERIMENTAL === "true";
1716
const frameworkToTest = getFrameworkToTest({ experimental: false });
1817
const { name: pm } = detectPackageManager();
18+
19+
beforeAll((ctx) => {
20+
recreateLogFolder({ experimental }, ctx);
21+
});
22+
1923
// Note: skipIf(frameworkToTest) makes it so that all the basic C3 functionality
2024
// tests are skipped in case we are testing a specific framework
2125
describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
2226
"E2E: Basic C3 functionality ",
2327
() => {
24-
beforeAll((ctx) => {
25-
recreateLogFolder({ experimental }, ctx as Suite);
26-
});
27-
2828
test({ experimental })("--version", async ({ logStream }) => {
2929
const { output } = await runC3(["--version"], [], logStream);
3030
expect(output).toEqual(version);
@@ -51,7 +51,7 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
5151
expect(output).toEqual(version);
5252
});
5353

54-
test({ experimental }).skipIf(process.platform === "win32")(
54+
test({ experimental }).skipIf(process.platform === "win32" || experimental)(
5555
"Using arrow keys + enter",
5656
async ({ logStream, project }) => {
5757
const { output } = await runC3(
@@ -82,7 +82,7 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
8282
);
8383

8484
expect(project.path).toExist();
85-
expect(output).toContain(`category Hello World Starter`);
85+
expect(output).toContain(`category Hello World example`);
8686
expect(output).toContain(`type Worker + Assets`);
8787
expect(output).toContain(`lang TypeScript`);
8888
expect(output).toContain(`no deploy`);
@@ -269,7 +269,7 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
269269
);
270270

271271
expect(project.path).toExist();
272-
expect(output).toContain(`category Hello World Starter`);
272+
expect(output).toContain(`category Hello World example`);
273273
expect(output).toContain(`type Worker only`);
274274
expect(output).toContain(`lang Python`);
275275
},
@@ -376,7 +376,7 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
376376
matcher: /What would you like to start with\?/,
377377
input: {
378378
type: "select",
379-
target: "Hello World Starter",
379+
target: "Hello World example",
380380
assertDefaultSelection: "Framework Starter",
381381
},
382382
},
@@ -442,3 +442,175 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
442442
});
443443
},
444444
);
445+
446+
describe.skipIf(frameworkToTest || isQuarantineMode())("help text", () => {
447+
test({ experimental })("--help", async ({ logStream }) => {
448+
if (experimental) {
449+
const { output } = await runC3(
450+
["--help", "--experimental"],
451+
[],
452+
logStream,
453+
);
454+
expect(normalizeOutput(output)).toMatchInlineSnapshot(`
455+
"create-cloudflare <version>
456+
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
457+
USAGE
458+
<USAGE>
459+
OPTIONS
460+
You have selected experimental mode - the options below are filtered to those that support experimental mode.
461+
directory
462+
The directory where the application should be created. Also used as the name of the application.
463+
If a path is provided that includes intermediary directories, only the base name will be used as the name of the application.
464+
--category=<value>
465+
Specifies the kind of templates that should be created
466+
Allowed Values:
467+
web-framework
468+
Framework Starter
469+
--type=<value>, -t
470+
When using a built-in template, specifies the type of application that should be created.
471+
Note that "--category" and "--template" are mutually exclusive options. If both are provided, "--category" will be used.
472+
--framework=<value>, -f
473+
The type of framework to use to create a web application (when using this option "--category" is coerced to "web-framework")
474+
When using the --framework option, C3 will dispatch to the official creation tool used by the framework (ex. "create-remix" is used for Remix).
475+
You may specify additional arguments to be passed directly to these underlying tools by adding them after a "--" argument, like so:
476+
npm create cloudflare -- --framework next -- --ts
477+
pnpm create cloudflare --framework next -- --ts
478+
Allowed Values:
479+
next, solid
480+
--platform=<value>
481+
Whether the application should be deployed to Pages or Workers. This is only applicable for Frameworks templates that support both Pages and Workers.
482+
Allowed Values:
483+
pages
484+
Create a web application that can be deployed to Pages.
485+
workers
486+
Create a web application that can be deployed to Workers (BETA).
487+
--lang=<value>
488+
The programming language of the template
489+
Allowed Values:
490+
ts, js, python
491+
--deploy, --no-deploy
492+
Deploy your application after it has been created
493+
--git, --no-git
494+
Initialize a local git repository for your application
495+
--open, --no-open
496+
Opens the deployed application in your browser (this option is ignored if the application is not deployed)
497+
--existing-script=<value>
498+
The name of an existing Cloudflare Workers script to clone locally (when using this option "--type" is coerced to "pre-existing").
499+
When "--existing-script" is specified, "deploy" will be ignored.
500+
--template=<value>
501+
An external template to be used when creating your project.
502+
Any "degit" compatible string may be specified. For example:
503+
npm create cloudflare my-project -- --template github:user/repo
504+
npm create cloudflare my-project -- --template [email protected]:user/repo
505+
npm create cloudflare my-project -- --template https://github.com/user/repo
506+
npm create cloudflare my-project -- --template [email protected]:user/repo#dev (branch)
507+
npm create cloudflare my-project -- --template [email protected]:user/repo#v1.2.3 (tag)
508+
npm create cloudflare my-project -- --template [email protected]:user/repo#1234abcd (commit)
509+
Note that subdirectories may also be used. For example:
510+
npm create cloudflare -- --template https://github.com/cloudflare/workers-sdk/templates/worker-r2
511+
--accept-defaults, --no-accept-defaults, -y
512+
Use all the default C3 options (each can also be overridden by specifying it)
513+
--auto-update, --no-auto-update
514+
Automatically uses the latest version of C3"
515+
`);
516+
} else {
517+
const { output } = await runC3(["--help"], [], logStream);
518+
expect(normalizeOutput(output)).toMatchInlineSnapshot(`
519+
"create-cloudflare <version>
520+
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
521+
USAGE
522+
<USAGE>
523+
OPTIONS
524+
directory
525+
The directory where the application should be created. Also used as the name of the application.
526+
If a path is provided that includes intermediary directories, only the base name will be used as the name of the application.
527+
--category=<value>
528+
Specifies the kind of templates that should be created
529+
Allowed Values:
530+
hello-world
531+
Hello World Starter
532+
web-framework
533+
Framework Starter
534+
demo
535+
Application Starter
536+
remote-template
537+
Template from a GitHub repo
538+
--type=<value>, -t
539+
When using a built-in template, specifies the type of application that should be created.
540+
Note that "--category" and "--template" are mutually exclusive options. If both are provided, "--category" will be used.
541+
Allowed Values:
542+
hello-world
543+
For processing requests, transforming responses, or API endpoints
544+
hello-world-assets-only
545+
For static sites (including SPAs) or when using your own backend
546+
hello-world-with-assets
547+
For static sites with an API or server-side rendering (SSR)
548+
hello-world-durable-object
549+
For multiplayer apps using WebSockets, or when you need synchronization
550+
hello-world-durable-object-with-assets
551+
For full-stack applications requiring static assets, an API, and real-time coordination
552+
common
553+
Create a Worker to route and forward requests to other services
554+
scheduled
555+
Create a Worker to be executed on a schedule for periodic (cron) jobs
556+
queues
557+
Get started with a Worker that processes background tasks and message batches with Cloudflare Queues
558+
openapi
559+
Get started building a basic API on Workers
560+
pre-existing
561+
Fetch a Worker initialized from the Cloudflare dashboard.
562+
--framework=<value>, -f
563+
The type of framework to use to create a web application (when using this option "--category" is coerced to "web-framework")
564+
When using the --framework option, C3 will dispatch to the official creation tool used by the framework (ex. "create-remix" is used for Remix).
565+
You may specify additional arguments to be passed directly to these underlying tools by adding them after a "--" argument, like so:
566+
npm create cloudflare -- --framework next -- --ts
567+
pnpm create cloudflare --framework next -- --ts
568+
Allowed Values:
569+
analog, angular, astro, docusaurus, gatsby, hono, next, nuxt, qwik, react, react-router, remix, solid, svelte, vue
570+
--platform=<value>
571+
Whether the application should be deployed to Pages or Workers. This is only applicable for Frameworks templates that support both Pages and Workers.
572+
Allowed Values:
573+
pages
574+
Create a web application that can be deployed to Pages.
575+
workers
576+
Create a web application that can be deployed to Workers (BETA).
577+
--lang=<value>
578+
The programming language of the template
579+
Allowed Values:
580+
ts, js, python
581+
--deploy, --no-deploy
582+
Deploy your application after it has been created
583+
--git, --no-git
584+
Initialize a local git repository for your application
585+
--open, --no-open
586+
Opens the deployed application in your browser (this option is ignored if the application is not deployed)
587+
--existing-script=<value>
588+
The name of an existing Cloudflare Workers script to clone locally (when using this option "--type" is coerced to "pre-existing").
589+
When "--existing-script" is specified, "deploy" will be ignored.
590+
--template=<value>
591+
An external template to be used when creating your project.
592+
Any "degit" compatible string may be specified. For example:
593+
npm create cloudflare my-project -- --template github:user/repo
594+
npm create cloudflare my-project -- --template [email protected]:user/repo
595+
npm create cloudflare my-project -- --template https://github.com/user/repo
596+
npm create cloudflare my-project -- --template [email protected]:user/repo#dev (branch)
597+
npm create cloudflare my-project -- --template [email protected]:user/repo#v1.2.3 (tag)
598+
npm create cloudflare my-project -- --template [email protected]:user/repo#1234abcd (commit)
599+
Note that subdirectories may also be used. For example:
600+
npm create cloudflare -- --template https://github.com/cloudflare/workers-sdk/templates/worker-r2
601+
--accept-defaults, --no-accept-defaults, -y
602+
Use all the default C3 options (each can also be overridden by specifying it)
603+
--auto-update, --no-auto-update
604+
Automatically uses the latest version of C3"
605+
`);
606+
}
607+
});
608+
});
609+
610+
function normalizeOutput(output: string): string {
611+
return output
612+
.replaceAll("\r\n", "\n")
613+
.replaceAll(/\n\n+/g, "\n")
614+
.replace(/create-cloudflare v\d+\.\d+\.\d+/, "create-cloudflare <version>")
615+
.replace(/USAGE\n[^\n]+/, `USAGE\n <USAGE>`);
616+
}

packages/create-cloudflare/src/helpers/args.ts

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { version } from "../../package.json";
55
import { reporter } from "../metrics";
66
import {
77
getFrameworkMap,
8+
getHelloWorldTemplateMap,
89
getNamesAndDescriptions,
9-
getTemplateMap,
10+
getOtherTemplateMap,
1011
} from "../templates";
1112
import { C3_DEFAULTS, WRANGLER_DEFAULTS } from "./cli";
1213
import type { PromptConfig } from "@cloudflare/cli/interactive";
@@ -69,10 +70,7 @@ export const cliDefinition: ArgumentsDefinition = {
6970
values(args) {
7071
const experimental = Boolean(args?.["experimental"]);
7172
if (experimental) {
72-
return [
73-
{ name: "hello-world", description: "Hello World Starter" },
74-
{ name: "web-framework", description: "Framework Starter" },
75-
];
73+
return [{ name: "web-framework", description: "Framework Starter" }];
7674
} else {
7775
return [
7876
{ name: "hello-world", description: "Hello World Starter" },
@@ -98,45 +96,10 @@ export const cliDefinition: ArgumentsDefinition = {
9896
`,
9997
values(args) {
10098
const experimental = Boolean(args?.["experimental"]);
101-
if (experimental) {
102-
return getNamesAndDescriptions(getTemplateMap({ experimental }));
103-
} else {
104-
return [
105-
{
106-
name: "hello-world",
107-
description: "A basic “Hello World” Cloudflare Worker.",
108-
},
109-
{
110-
name: "hello-world-durable-object",
111-
description:
112-
"A basic “Hello World” Cloudflare Worker with a Durable Worker.",
113-
},
114-
{
115-
name: "common",
116-
description:
117-
"A Cloudflare Worker which implements a common example of routing/proxying functionalities.",
118-
},
119-
{
120-
name: "scheduled",
121-
description:
122-
"A scheduled Cloudflare Worker (triggered via Cron Triggers).",
123-
},
124-
{
125-
name: "queues",
126-
description:
127-
"A Cloudflare Worker which is both a consumer and produced of Queues.",
128-
},
129-
{
130-
name: "openapi",
131-
description: "A Worker implementing an OpenAPI REST endpoint.",
132-
},
133-
{
134-
name: "pre-existing",
135-
description:
136-
"Fetch a Worker initialized from the Cloudflare dashboard.",
137-
},
138-
];
139-
}
99+
return getNamesAndDescriptions({
100+
...getHelloWorldTemplateMap({ experimental }),
101+
...getOtherTemplateMap({ experimental }),
102+
});
140103
},
141104
},
142105
{
@@ -151,7 +114,7 @@ export const cliDefinition: ArgumentsDefinition = {
151114
You may specify additional arguments to be passed directly to these underlying tools by adding them after a "--" argument, like so:
152115
153116
npm create cloudflare -- --framework next -- --ts
154-
pnpm create clouldfare --framework next -- --ts
117+
pnpm create cloudflare --framework next -- --ts
155118
`,
156119
values: (args) =>
157120
getNamesAndDescriptions(

0 commit comments

Comments
 (0)