Skip to content

Commit b24497d

Browse files
graduate C3 React (Workers) template (#8371)
Resolves DEVX-1697
1 parent ca60010 commit b24497d

File tree

17 files changed

+106
-89
lines changed

17 files changed

+106
-89
lines changed

.changeset/mighty-moments-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
graduate C3 React (Workers) template

packages/create-cloudflare/e2e-tests/frameworks/framework-test-config-experimental.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,6 @@ export default function getFrameworkTestConfigExperimental() {
1717
},
1818
flags: ["--style", "sass"],
1919
},
20-
react: {
21-
promptHandlers: [
22-
{
23-
matcher: /Select a variant:/,
24-
input: [keys.enter],
25-
},
26-
],
27-
unsupportedOSs: ["win32"],
28-
testCommitMessage: true,
29-
verifyDeploy: {
30-
route: "/",
31-
// Note that this is the text in the static HTML that is returned
32-
// This React SPA will change this at runtime but we are only making a fetch request
33-
// not actually running the client side JS.
34-
expectedText: "Vite + React + TS",
35-
},
36-
verifyPreview: {
37-
route: "/",
38-
previewArgs: ["--host=127.0.0.1"],
39-
// Note that this is the text in the static HTML that is returned
40-
// This React SPA will change this at runtime but we are only making a fetch request
41-
// not actually running the client side JS.
42-
expectedText: "Vite + React + TS",
43-
},
44-
},
4520
gatsby: {
4621
unsupportedPms: ["bun", "pnpm"],
4722
promptHandlers: [

packages/create-cloudflare/e2e-tests/frameworks/framework-test-config.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function getFrameworkTestConfig(pm: string) {
3131
"strict",
3232
],
3333
},
34-
["docusaurus:pages"]: {
34+
"docusaurus:pages": {
3535
argv: ["--platform", "pages"],
3636
unsupportedPms: ["bun"],
3737
testCommitMessage: true,
@@ -57,7 +57,7 @@ export default function getFrameworkTestConfig(pm: string) {
5757
},
5858
],
5959
},
60-
["docusaurus:workers"]: {
60+
"docusaurus:workers": {
6161
argv: ["--platform", "workers"],
6262
unsupportedPms: ["bun"],
6363
testCommitMessage: true,
@@ -265,7 +265,8 @@ export default function getFrameworkTestConfig(pm: string) {
265265
expectedText: "C3_TEST",
266266
},
267267
},
268-
react: {
268+
"react:pages": {
269+
argv: ["--platform", "pages"],
269270
promptHandlers: [
270271
{
271272
matcher: /Select a variant:/,
@@ -284,6 +285,34 @@ export default function getFrameworkTestConfig(pm: string) {
284285
expectedText: "Vite + React",
285286
},
286287
},
288+
"react:workers": {
289+
argv: ["--platform", "workers"],
290+
promptHandlers: [
291+
{
292+
matcher: /Select a variant:/,
293+
input: [keys.enter],
294+
},
295+
],
296+
unsupportedOSs: ["win32"],
297+
testCommitMessage: true,
298+
verifyDeploy: {
299+
route: "/",
300+
// Note that this is the text in the static HTML that is returned
301+
// This React SPA will change this at runtime but we are only making a fetch request
302+
// not actually running the client side JS.
303+
expectedText: "Vite + React + TS",
304+
},
305+
verifyPreview: {
306+
route: "/",
307+
// We need to run the preview on the specific IP address on which we make the request.
308+
// By default `vite preview` runs on `localhost` that doesn't always include 127.0.0.1.
309+
previewArgs: ["--host=127.0.0.1"],
310+
// Note that this is the text in the static HTML that is returned
311+
// This React SPA will change this at runtime but we are only making a fetch request
312+
// not actually running the client side JS.
313+
expectedText: "Vite + React + TS",
314+
},
315+
},
287316
solid: {
288317
promptHandlers: [
289318
{

packages/create-cloudflare/src/templates.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import honoTemplateExperimental from "templates-experimental/hono/c3";
2828
import nextTemplateExperimental from "templates-experimental/next/c3";
2929
import nuxtTemplateExperimental from "templates-experimental/nuxt/c3";
3030
import qwikTemplateExperimental from "templates-experimental/qwik/c3";
31-
import reactTemplateExperimental from "templates-experimental/react/c3";
3231
import remixTemplateExperimental from "templates-experimental/remix/c3";
3332
import solidTemplateExperimental from "templates-experimental/solid/c3";
3433
import svelteTemplateExperimental from "templates-experimental/svelte/c3";
@@ -188,7 +187,6 @@ export function getFrameworkMap({ experimental = false }): TemplateMap {
188187
next: nextTemplateExperimental,
189188
nuxt: nuxtTemplateExperimental,
190189
qwik: qwikTemplateExperimental,
191-
react: reactTemplateExperimental,
192190
remix: remixTemplateExperimental,
193191
solid: solidTemplateExperimental,
194192
svelte: svelteTemplateExperimental,
Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,9 @@
1-
import { logRaw } from "@cloudflare/cli";
2-
import { inputPrompt } from "@cloudflare/cli/interactive";
3-
import { runFrameworkGenerator } from "frameworks/index";
4-
import { detectPackageManager } from "helpers/packageManagers";
5-
import type { TemplateConfig } from "../../src/templates";
6-
import type { C3Context } from "types";
1+
import pages from "./pages/c3";
2+
import workers from "./workers/c3";
3+
import type { MultiPlatformTemplateConfig } from "../../src/templates";
74

8-
const { npm } = detectPackageManager();
9-
10-
const generate = async (ctx: C3Context) => {
11-
const variant = await inputPrompt({
12-
type: "select",
13-
question: "Select a variant:",
14-
label: "variant",
15-
options: variantsOptions,
16-
defaultValue: variantsOptions[0].value,
17-
});
18-
19-
await runFrameworkGenerator(ctx, [ctx.project.name, "--template", variant]);
20-
21-
logRaw("");
22-
};
23-
24-
const variantsOptions = [
25-
{
26-
value: "react-ts",
27-
label: "TypeScript",
28-
},
29-
{
30-
value: "react-swc-ts",
31-
label: "TypeScript + SWC",
32-
},
33-
{
34-
value: "react",
35-
label: "JavaScript",
36-
},
37-
{
38-
value: "react-swc",
39-
label: "JavaScript + SWC",
40-
},
41-
];
42-
43-
const config: TemplateConfig = {
44-
configVersion: 1,
45-
id: "react",
46-
// React's documentation now recommends using create-vite.
47-
frameworkCli: "create-vite",
5+
const config: MultiPlatformTemplateConfig = {
486
displayName: "React",
49-
platform: "pages",
50-
generate,
51-
transformPackageJson: async () => ({
52-
scripts: {
53-
deploy: `${npm} run build && wrangler pages deploy ./dist`,
54-
preview: `${npm} run build && wrangler pages dev ./dist`,
55-
},
56-
}),
57-
devScript: "dev",
58-
deployScript: "deploy",
59-
previewScript: "preview",
7+
platformVariants: { pages, workers },
608
};
619
export default config;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { logRaw } from "@cloudflare/cli";
2+
import { inputPrompt } from "@cloudflare/cli/interactive";
3+
import { runFrameworkGenerator } from "frameworks/index";
4+
import { detectPackageManager } from "helpers/packageManagers";
5+
import type { TemplateConfig } from "../../../src/templates";
6+
import type { C3Context } from "types";
7+
8+
const { npm } = detectPackageManager();
9+
10+
const generate = async (ctx: C3Context) => {
11+
const variant = await inputPrompt({
12+
type: "select",
13+
question: "Select a variant:",
14+
label: "variant",
15+
options: variantsOptions,
16+
defaultValue: variantsOptions[0].value,
17+
});
18+
19+
await runFrameworkGenerator(ctx, [ctx.project.name, "--template", variant]);
20+
21+
logRaw("");
22+
};
23+
24+
const variantsOptions = [
25+
{
26+
value: "react-ts",
27+
label: "TypeScript",
28+
},
29+
{
30+
value: "react-swc-ts",
31+
label: "TypeScript + SWC",
32+
},
33+
{
34+
value: "react",
35+
label: "JavaScript",
36+
},
37+
{
38+
value: "react-swc",
39+
label: "JavaScript + SWC",
40+
},
41+
];
42+
43+
const config: TemplateConfig = {
44+
configVersion: 1,
45+
id: "react",
46+
// React's documentation now recommends using create-vite.
47+
frameworkCli: "create-vite",
48+
displayName: "React",
49+
platform: "pages",
50+
path: "templates/react/pages",
51+
generate,
52+
transformPackageJson: async () => ({
53+
scripts: {
54+
deploy: `${npm} run build && wrangler pages deploy ./dist`,
55+
preview: `${npm} run build && wrangler pages dev ./dist`,
56+
},
57+
}),
58+
devScript: "dev",
59+
deployScript: "deploy",
60+
previewScript: "preview",
61+
};
62+
export default config;

packages/create-cloudflare/templates-experimental/react/c3.ts renamed to packages/create-cloudflare/templates/react/workers/c3.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { readJSON, usesTypescript, writeJSON } from "helpers/files";
88
import { detectPackageManager } from "helpers/packageManagers";
99
import { installPackages } from "helpers/packages";
1010
import * as recast from "recast";
11-
import type { TemplateConfig } from "../../src/templates";
11+
import type { TemplateConfig } from "../../../src/templates";
1212
import type { types } from "recast";
1313
import type { C3Context } from "types";
1414

@@ -156,7 +156,7 @@ const config: TemplateConfig = {
156156
frameworkCli: "create-vite",
157157
displayName: "React",
158158
platform: "workers",
159-
path: "templates-experimental/react",
159+
path: "templates/react/workers",
160160
copyFiles: {
161161
variants: {
162162
ts: {

0 commit comments

Comments
 (0)