create-cloudflare 0.0.0-dae7bd4dd → 0.0.0-db0172707

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/cli.js +638 -651
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +7 -7
  4. package/templates/astro/c3.ts +93 -5
  5. package/templates/hello-world/c3.ts +2 -3
  6. package/templates/hello-world-durable-object/c3.ts +2 -2
  7. package/templates/hello-world-durable-object/js/src/index.js +9 -10
  8. package/templates/hello-world-durable-object/js/wrangler.jsonc +1 -1
  9. package/templates/hello-world-durable-object/ts/src/index.ts +9 -10
  10. package/templates/hello-world-durable-object/ts/wrangler.jsonc +1 -1
  11. package/templates/react/workers/js/src/assets/Cloudflare_Logo.svg +5 -7
  12. package/templates/remix/c3.ts +63 -5
  13. package/{templates/astro/workers → templates-experimental/astro}/c3.ts +2 -2
  14. package/templates-experimental/astro/templates/js/public/.assetsignore +4 -0
  15. package/templates-experimental/astro/templates/ts/public/.assetsignore +4 -0
  16. package/{templates → templates-experimental}/hello-world-assets-only/c3.ts +3 -4
  17. package/{templates → templates-experimental}/hello-world-durable-object-with-assets/c3.ts +3 -3
  18. package/{templates → templates-experimental}/hello-world-with-assets/c3.ts +4 -3
  19. package/{templates/remix/workers → templates-experimental/remix}/c3.ts +2 -2
  20. package/templates/astro/pages/c3.ts +0 -98
  21. package/templates/astro/workers/templates/js/public/.assetsignore +0 -2
  22. package/templates/astro/workers/templates/ts/public/.assetsignore +0 -2
  23. package/templates/remix/pages/c3.ts +0 -68
  24. /package/templates/astro/{pages/templates → templates}/js/wrangler.jsonc +0 -0
  25. /package/templates/astro/{workers/templates → templates}/ts/src/env.d.ts +0 -0
  26. /package/templates/{hello-world-with-assets → astro/templates}/ts/worker-configuration.d.ts +0 -0
  27. /package/templates/astro/{pages/templates → templates}/ts/wrangler.jsonc +0 -0
  28. /package/templates/remix/{pages/templates → templates}/worker-configuration.d.ts +0 -0
  29. /package/templates/remix/{pages/templates → templates}/wrangler.jsonc +0 -0
  30. /package/{templates/astro/workers → templates-experimental/astro}/templates/js/wrangler.jsonc +0 -0
  31. /package/{templates/astro/pages → templates-experimental/astro}/templates/ts/src/env.d.ts +0 -0
  32. /package/{templates/astro/pages → templates-experimental/astro}/templates/ts/worker-configuration.d.ts +0 -0
  33. /package/{templates/astro/workers → templates-experimental/astro}/templates/ts/wrangler.jsonc +0 -0
  34. /package/{templates → templates-experimental}/hello-world-assets-only/templates/package.json +0 -0
  35. /package/{templates → templates-experimental}/hello-world-assets-only/templates/public/index.html +0 -0
  36. /package/{templates → templates-experimental}/hello-world-assets-only/templates/wrangler.jsonc +0 -0
  37. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/.editorconfig +0 -0
  38. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/.prettierrc +0 -0
  39. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/__dot__gitignore +0 -0
  40. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/package.json +0 -0
  41. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/public/index.html +0 -0
  42. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/src/index.js +0 -0
  43. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/js/wrangler.jsonc +0 -0
  44. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/.editorconfig +0 -0
  45. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/.prettierrc +0 -0
  46. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/__dot__gitignore +0 -0
  47. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/package.json +0 -0
  48. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/public/index.html +0 -0
  49. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/src/index.ts +0 -0
  50. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/tsconfig.json +0 -0
  51. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/worker-configuration.d.ts +0 -0
  52. /package/{templates → templates-experimental}/hello-world-durable-object-with-assets/ts/wrangler.jsonc +0 -0
  53. /package/{templates → templates-experimental}/hello-world-with-assets/js/.editorconfig +0 -0
  54. /package/{templates → templates-experimental}/hello-world-with-assets/js/.prettierrc +0 -0
  55. /package/{templates → templates-experimental}/hello-world-with-assets/js/__dot__gitignore +0 -0
  56. /package/{templates → templates-experimental}/hello-world-with-assets/js/package.json +0 -0
  57. /package/{templates → templates-experimental}/hello-world-with-assets/js/public/index.html +0 -0
  58. /package/{templates → templates-experimental}/hello-world-with-assets/js/src/index.js +0 -0
  59. /package/{templates → templates-experimental}/hello-world-with-assets/js/test/index.spec.js +0 -0
  60. /package/{templates → templates-experimental}/hello-world-with-assets/js/vitest.config.js +0 -0
  61. /package/{templates → templates-experimental}/hello-world-with-assets/js/wrangler.jsonc +0 -0
  62. /package/{templates → templates-experimental}/hello-world-with-assets/py/__dot__gitignore +0 -0
  63. /package/{templates → templates-experimental}/hello-world-with-assets/py/package.json +0 -0
  64. /package/{templates → templates-experimental}/hello-world-with-assets/py/public/index.html +0 -0
  65. /package/{templates → templates-experimental}/hello-world-with-assets/py/src/entry.py +0 -0
  66. /package/{templates → templates-experimental}/hello-world-with-assets/py/wrangler.jsonc +0 -0
  67. /package/{templates → templates-experimental}/hello-world-with-assets/ts/.editorconfig +0 -0
  68. /package/{templates → templates-experimental}/hello-world-with-assets/ts/.prettierrc +0 -0
  69. /package/{templates → templates-experimental}/hello-world-with-assets/ts/__dot__gitignore +0 -0
  70. /package/{templates → templates-experimental}/hello-world-with-assets/ts/package.json +0 -0
  71. /package/{templates → templates-experimental}/hello-world-with-assets/ts/public/index.html +0 -0
  72. /package/{templates → templates-experimental}/hello-world-with-assets/ts/src/index.ts +0 -0
  73. /package/{templates → templates-experimental}/hello-world-with-assets/ts/test/index.spec.ts +0 -0
  74. /package/{templates → templates-experimental}/hello-world-with-assets/ts/test/tsconfig.json +0 -0
  75. /package/{templates → templates-experimental}/hello-world-with-assets/ts/tsconfig.json +0 -0
  76. /package/{templates → templates-experimental}/hello-world-with-assets/ts/vitest.config.mts +0 -0
  77. /package/{templates/astro/workers/templates → templates-experimental/hello-world-with-assets}/ts/worker-configuration.d.ts +0 -0
  78. /package/{templates → templates-experimental}/hello-world-with-assets/ts/wrangler.jsonc +0 -0
  79. /package/{templates/remix/workers → templates-experimental/remix}/templates/public/.assetsignore +0 -0
  80. /package/{templates/remix/workers → templates-experimental/remix}/templates/worker-configuration.d.ts +0 -0
  81. /package/{templates/remix/workers → templates-experimental/remix}/templates/wrangler.toml +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cloudflare",
3
- "version": "0.0.0-dae7bd4dd",
3
+ "version": "0.0.0-db0172707",
4
4
  "description": "A CLI for creating and deploying new applications to Cloudflare.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -30,7 +30,7 @@
30
30
  "@babel/parser": "^7.21.3",
31
31
  "@babel/types": "^7.21.4",
32
32
  "@clack/prompts": "^0.6.3",
33
- "@cloudflare/workers-types": "^4.20250319.0",
33
+ "@cloudflare/workers-types": "^4.20250317.0",
34
34
  "@iarna/toml": "^3.0.0",
35
35
  "@types/command-exists": "^1.2.0",
36
36
  "@types/cross-spawn": "^6.0.2",
@@ -65,17 +65,17 @@
65
65
  "undici": "^5.28.5",
66
66
  "vite": "^5.4.14",
67
67
  "vite-tsconfig-paths": "^4.0.8",
68
- "vitest": "~3.0.8",
68
+ "vitest": "~3.0.5",
69
69
  "which-pm-runs": "^1.1.0",
70
70
  "wrap-ansi": "^9.0.0",
71
71
  "xdg-app-paths": "^8.3.0",
72
72
  "yargs": "^17.7.2",
73
- "@cloudflare/cli": "1.1.1",
74
73
  "@cloudflare/eslint-config-worker": "1.1.0",
75
- "@cloudflare/vite-plugin": "0.0.0-dae7bd4dd",
76
- "@cloudflare/workers-tsconfig": "0.0.0",
74
+ "@cloudflare/cli": "1.1.1",
77
75
  "@cloudflare/mock-npm-registry": "0.0.0",
78
- "wrangler": "0.0.0-dae7bd4dd"
76
+ "@cloudflare/workers-tsconfig": "0.0.0",
77
+ "wrangler": "0.0.0-db0172707",
78
+ "@cloudflare/vite-plugin": "0.0.0-db0172707"
79
79
  },
80
80
  "engines": {
81
81
  "node": ">=18.14.1"
@@ -1,9 +1,97 @@
1
- import pages from "./pages/c3";
2
- import workers from "./workers/c3";
3
- import type { MultiPlatformTemplateConfig } from "../../src/templates";
1
+ import { logRaw, updateStatus } from "@cloudflare/cli";
2
+ import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
+ import { runFrameworkGenerator } from "frameworks/index";
4
+ import { transformFile } from "helpers/codemod";
5
+ import { runCommand } from "helpers/command";
6
+ import { usesTypescript } from "helpers/files";
7
+ import { detectPackageManager } from "helpers/packageManagers";
8
+ import * as recast from "recast";
9
+ import type { TemplateConfig } from "../../src/templates";
10
+ import type { C3Context, PackageJson } from "types";
4
11
 
5
- const config: MultiPlatformTemplateConfig = {
12
+ const { npx } = detectPackageManager();
13
+
14
+ const generate = async (ctx: C3Context) => {
15
+ await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
16
+
17
+ logRaw(""); // newline
18
+ };
19
+
20
+ const configure = async () => {
21
+ await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
22
+ silent: true,
23
+ startText: "Installing adapter",
24
+ doneText: `${brandColor("installed")} ${dim(
25
+ `via \`${npx} astro add cloudflare\``,
26
+ )}`,
27
+ });
28
+
29
+ updateAstroConfig();
30
+ };
31
+
32
+ const updateAstroConfig = () => {
33
+ const filePath = "astro.config.mjs";
34
+
35
+ updateStatus(`Updating configuration in ${blue(filePath)}`);
36
+
37
+ transformFile(filePath, {
38
+ visitCallExpression: function (n) {
39
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
40
+ if (callee.name !== "cloudflare") {
41
+ return this.traverse(n);
42
+ }
43
+
44
+ const b = recast.types.builders;
45
+ n.node.arguments = [
46
+ b.objectExpression([
47
+ b.objectProperty(
48
+ b.identifier("platformProxy"),
49
+ b.objectExpression([
50
+ b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
51
+ ]),
52
+ ),
53
+ ]),
54
+ ];
55
+
56
+ return false;
57
+ },
58
+ });
59
+ };
60
+
61
+ const config: TemplateConfig = {
62
+ configVersion: 1,
63
+ id: "astro",
64
+ frameworkCli: "create-astro",
65
+ platform: "pages",
6
66
  displayName: "Astro",
7
- platformVariants: { pages, workers },
67
+ copyFiles: {
68
+ async selectVariant(ctx) {
69
+ // Note: this `selectVariant` function should not be needed
70
+ // this is just a quick workaround until
71
+ // https://github.com/cloudflare/workers-sdk/issues/7495
72
+ // is resolved
73
+ return usesTypescript(ctx) ? "ts" : "js";
74
+ },
75
+ variants: {
76
+ js: {
77
+ path: "./templates/js",
78
+ },
79
+ ts: {
80
+ path: "./templates/ts",
81
+ },
82
+ },
83
+ },
84
+ devScript: "dev",
85
+ deployScript: "deploy",
86
+ previewScript: "preview",
87
+ generate,
88
+ configure,
89
+ transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
90
+ scripts: {
91
+ deploy: `astro build && wrangler pages deploy`,
92
+ preview: `astro build && wrangler pages dev`,
93
+ ...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
94
+ },
95
+ }),
8
96
  };
9
97
  export default config;
@@ -5,9 +5,8 @@ import type { TemplateConfig } from "../../src/templates";
5
5
  export default {
6
6
  configVersion: 1,
7
7
  id: "hello-world",
8
- displayName: "Worker only",
9
- description:
10
- "For processing requests, transforming responses, or API endpoints",
8
+ displayName: "Hello World Worker",
9
+ description: "Get started with a basic Worker in the language of your choice",
11
10
  platform: "workers",
12
11
  async configure(ctx) {
13
12
  if (ctx.args.lang === "python") {
@@ -1,9 +1,9 @@
1
1
  export default {
2
2
  configVersion: 1,
3
3
  id: "hello-world-durable-object",
4
- displayName: "Worker + Durable Objects",
4
+ displayName: "Hello World Worker Using Durable Objects",
5
5
  description:
6
- "For multiplayer apps using WebSockets, or when you need synchronization",
6
+ "Get started with a basic stateful app to build projects like real-time chats, collaborative apps, and multiplayer games",
7
7
  platform: "workers",
8
8
  copyFiles: {
9
9
  variants: {
@@ -52,18 +52,17 @@ export default {
52
52
  * @returns {Promise<Response>} The response to be sent back to the client
53
53
  */
54
54
  async fetch(request, env, ctx) {
55
- // Create a `DurableObjectId` for an instance of the `MyDurableObject`
56
- // class named "foo". Requests from all Workers to the instance named
57
- // "foo" will go to a single globally unique Durable Object instance.
58
- const id = env.MY_DURABLE_OBJECT.idFromName("foo");
55
+ // We will create a `DurableObjectId` using the pathname from the Worker request
56
+ // This id refers to a unique instance of our 'MyDurableObject' class above
57
+ let id = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
59
58
 
60
- // Create a stub to open a communication channel with the Durable
61
- // Object instance.
62
- const stub = env.MY_DURABLE_OBJECT.get(id);
59
+ // This stub creates a communication channel with the Durable Object instance
60
+ // The Durable Object constructor will be invoked upon the first call for a given id
61
+ let stub = env.MY_DURABLE_OBJECT.get(id);
63
62
 
64
- // Call the `sayHello()` RPC method on the stub to invoke the method on
65
- // the remote Durable Object instance
66
- const greeting = await stub.sayHello("world");
63
+ // We call the `sayHello()` RPC method on the stub to invoke the method on the remote
64
+ // Durable Object instance
65
+ let greeting = await stub.sayHello("world");
67
66
 
68
67
  return new Response(greeting);
69
68
  },
@@ -4,7 +4,7 @@
4
4
  "compatibility_date": "<TBD>",
5
5
  "migrations": [
6
6
  {
7
- "new_sqlite_classes": [
7
+ "new_classes": [
8
8
  "MyDurableObject"
9
9
  ],
10
10
  "tag": "v1"
@@ -48,18 +48,17 @@ export default {
48
48
  * @returns The response to be sent back to the client
49
49
  */
50
50
  async fetch(request, env, ctx): Promise<Response> {
51
- // Create a `DurableObjectId` for an instance of the `MyDurableObject`
52
- // class named "foo". Requests from all Workers to the instance named
53
- // "foo" will go to a single globally unique Durable Object instance.
54
- const id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName("foo");
51
+ // We will create a `DurableObjectId` using the pathname from the Worker request
52
+ // This id refers to a unique instance of our 'MyDurableObject' class above
53
+ let id: DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
55
54
 
56
- // Create a stub to open a communication channel with the Durable
57
- // Object instance.
58
- const stub = env.MY_DURABLE_OBJECT.get(id);
55
+ // This stub creates a communication channel with the Durable Object instance
56
+ // The Durable Object constructor will be invoked upon the first call for a given id
57
+ let stub = env.MY_DURABLE_OBJECT.get(id);
59
58
 
60
- // Call the `sayHello()` RPC method on the stub to invoke the method on
61
- // the remote Durable Object instance
62
- const greeting = await stub.sayHello("world");
59
+ // We call the `sayHello()` RPC method on the stub to invoke the method on the remote
60
+ // Durable Object instance
61
+ let greeting = await stub.sayHello("world");
63
62
 
64
63
  return new Response(greeting);
65
64
  },
@@ -4,7 +4,7 @@
4
4
  "compatibility_date": "<TBD>",
5
5
  "migrations": [
6
6
  {
7
- "new_sqlite_classes": [
7
+ "new_classes": [
8
8
  "MyDurableObject"
9
9
  ],
10
10
  "tag": "v1"
@@ -4,10 +4,8 @@
4
4
  viewBox="0 0 822.8 355.5" style="enable-background:new 0 0 822.8 355.5;" xml:space="preserve">
5
5
  <style type="text/css">
6
6
  .st0{fill:#FFFFFF;}
7
- @media(prefers-color-scheme:light){.st0{fill:#404242;}}
8
- .st1{fill:#FFFFFF;}
9
- .st2{fill:#FBAE40;}
10
- .st3{fill:#F58220;}
7
+ .st1{fill:#FBAE40;}
8
+ .st2{fill:#F58220;}
11
9
  </style>
12
10
  <g id="Page-1">
13
11
  <path id="CLOUDFLARE-_xAE_" class="st0" d="M772.2,252.6c-3.4,0-6.1-2.7-6.1-6.1c0-3.3,2.7-6.1,6.1-6.1c3.3,0,6.1,2.7,6.1,6.1
@@ -26,13 +24,13 @@
26
24
  M102.7,274.6c-2.2,4.9-6.8,8.4-12.8,8.4c-8.5,0-14.3-7.1-14.3-15.1v-0.2c0-8.1,5.7-15,14.2-15c6.4,0,11.3,3.9,13.3,9.3h16.4
27
25
  c-2.6-13.4-14.4-23.3-29.6-23.3c-17.3,0-30.3,13.1-30.3,29.2v0.2c0,16.1,12.8,29,30.1,29c14.8,0,26.4-9.6,29.4-22.4L102.7,274.6z"
28
26
  />
29
- <path id="flare" class="st1" d="M734.5,150.4l-40.7-24.7c-0.6-0.1-4.4,0.3-6.4-0.7c-1.4-0.7-2.5-1.9-3.2-4c-3.2,0-175.5,0-175.5,0
27
+ <path id="flare" class="st0" d="M734.5,150.4l-40.7-24.7c-0.6-0.1-4.4,0.3-6.4-0.7c-1.4-0.7-2.5-1.9-3.2-4c-3.2,0-175.5,0-175.5,0
30
28
  v91.8h225.8V150.4z"/>
31
- <path id="right-cloud" class="st2" d="M692.2,125.8c-0.8,0-1.5,0.6-1.8,1.4l-4.8,16.7c-2.1,7.2-1.3,13.8,2.2,18.7
29
+ <path id="right-cloud" class="st1" d="M692.2,125.8c-0.8,0-1.5,0.6-1.8,1.4l-4.8,16.7c-2.1,7.2-1.3,13.8,2.2,18.7
32
30
  c3.2,4.5,8.6,7.1,15.1,7.4l26.2,1.6c0.8,0,1.5,0.4,1.9,1c0.4,0.6,0.5,1.5,0.3,2.2c-0.4,1.2-1.6,2.1-2.9,2.2l-27.3,1.6
33
31
  c-14.8,0.7-30.7,12.6-36.3,27.2l-2,5.1c-0.4,1,0.3,2,1.4,2H758c1.1,0,2.1-0.7,2.4-1.8c1.6-5.8,2.5-11.9,2.5-18.2
34
32
  c0-37-30.2-67.2-67.3-67.2C694.5,125.7,693.3,125.7,692.2,125.8z"/>
35
- <path id="left-cloud" class="st3" d="M656.4,204.6c2.1-7.2,1.3-13.8-2.2-18.7c-3.2-4.5-8.6-7.1-15.1-7.4L516,176.9
33
+ <path id="left-cloud" class="st2" d="M656.4,204.6c2.1-7.2,1.3-13.8-2.2-18.7c-3.2-4.5-8.6-7.1-15.1-7.4L516,176.9
36
34
  c-0.8,0-1.5-0.4-1.9-1c-0.4-0.6-0.5-1.4-0.3-2.2c0.4-1.2,1.6-2.1,2.9-2.2l124.2-1.6c14.7-0.7,30.7-12.6,36.3-27.2l7.1-18.5
37
35
  c0.3-0.8,0.4-1.6,0.2-2.4c-8-36.2-40.3-63.2-78.9-63.2c-35.6,0-65.8,23-76.6,54.9c-7-5.2-15.9-8-25.5-7.1
38
36
  c-17.1,1.7-30.8,15.4-32.5,32.5c-0.4,4.4-0.1,8.7,0.9,12.7c-27.9,0.8-50.2,23.6-50.2,51.7c0,2.5,0.2,5,0.5,7.5
@@ -1,9 +1,67 @@
1
- import pages from "./pages/c3";
2
- import workers from "./workers/c3";
3
- import type { MultiPlatformTemplateConfig } from "../../src/templates";
1
+ import { logRaw } from "@cloudflare/cli";
2
+ import { brandColor, dim } from "@cloudflare/cli/colors";
3
+ import { spinner } from "@cloudflare/cli/interactive";
4
+ import { runFrameworkGenerator } from "frameworks/index";
5
+ import { transformFile } from "helpers/codemod";
6
+ import { detectPackageManager } from "helpers/packageManagers";
7
+ import type { TemplateConfig } from "../../src/templates";
8
+ import type { C3Context } from "types";
4
9
 
5
- const config: MultiPlatformTemplateConfig = {
10
+ const { npm } = detectPackageManager();
11
+
12
+ const generate = async (ctx: C3Context) => {
13
+ await runFrameworkGenerator(ctx, [
14
+ ctx.project.name,
15
+ "--template",
16
+ "https://github.com/remix-run/remix/tree/main/templates/cloudflare",
17
+ ]);
18
+
19
+ logRaw(""); // newline
20
+ };
21
+
22
+ const configure = async () => {
23
+ const typeDefsPath = "load-context.ts";
24
+
25
+ const s = spinner();
26
+ s.start(`Updating \`${typeDefsPath}\``);
27
+
28
+ // Remove the empty Env declaration from the template to allow the type from
29
+ // worker-configuration.d.ts to take over
30
+ transformFile(typeDefsPath, {
31
+ visitTSInterfaceDeclaration(n) {
32
+ if (n.node.id.type === "Identifier" && n.node.id.name !== "Env") {
33
+ return this.traverse(n);
34
+ }
35
+
36
+ // Removes the node
37
+ n.replace();
38
+ return false;
39
+ },
40
+ });
41
+
42
+ s.stop(`${brandColor("updated")} \`${dim(typeDefsPath)}\``);
43
+ };
44
+
45
+ const config: TemplateConfig = {
46
+ configVersion: 1,
47
+ id: "remix",
48
+ frameworkCli: "create-remix",
49
+ platform: "pages",
6
50
  displayName: "Remix",
7
- platformVariants: { pages, workers },
51
+ copyFiles: {
52
+ path: "./templates",
53
+ },
54
+ generate,
55
+ configure,
56
+ transformPackageJson: async () => ({
57
+ scripts: {
58
+ deploy: `${npm} run build && wrangler pages deploy`,
59
+ preview: `${npm} run build && wrangler pages dev`,
60
+ "cf-typegen": `wrangler types`,
61
+ },
62
+ }),
63
+ devScript: "dev",
64
+ deployScript: "deploy",
65
+ previewScript: "preview",
8
66
  };
9
67
  export default config;
@@ -6,7 +6,7 @@ import { runCommand } from "helpers/command";
6
6
  import { usesTypescript } from "helpers/files";
7
7
  import { detectPackageManager } from "helpers/packageManagers";
8
8
  import * as recast from "recast";
9
- import type { TemplateConfig } from "../../../src/templates";
9
+ import type { TemplateConfig } from "../../src/templates";
10
10
  import type { C3Context, PackageJson } from "types";
11
11
 
12
12
  const { npx } = detectPackageManager();
@@ -84,7 +84,7 @@ const config: TemplateConfig = {
84
84
  devScript: "dev",
85
85
  deployScript: "deploy",
86
86
  previewScript: "preview",
87
- path: "templates/astro/workers",
87
+ path: "templates-experimental/astro",
88
88
  generate,
89
89
  configure,
90
90
  transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
@@ -0,0 +1,4 @@
1
+ _worker.js
2
+ _routes.json
3
+ _headers
4
+ _redirects
@@ -0,0 +1,4 @@
1
+ _worker.js
2
+ _routes.json
3
+ _headers
4
+ _redirects
@@ -3,10 +3,9 @@ import type { TemplateConfig } from "../../src/templates";
3
3
  const config: TemplateConfig = {
4
4
  configVersion: 1,
5
5
  id: "hello-world-assets-only",
6
- path: "templates/hello-world-assets-only",
7
- displayName: "Assets only",
8
- description:
9
- "For static sites (including SPAs) or when using your own backend",
6
+ path: "templates-experimental/hello-world-assets-only",
7
+ displayName: "Hello World - Assets-only",
8
+ description: "Get started with a basic Worker that only serves static assets",
10
9
  platform: "workers",
11
10
  copyFiles: {
12
11
  path: "./templates",
@@ -3,10 +3,10 @@ import type { TemplateConfig } from "../../src/templates";
3
3
  const config: TemplateConfig = {
4
4
  configVersion: 1,
5
5
  id: "hello-world-durable-object-with-assets",
6
- path: "templates/hello-world-durable-object-with-assets",
7
- displayName: "Worker + Durable Objects + Assets",
6
+ path: "templates-experimental/hello-world-durable-object-with-assets",
7
+ displayName: "Hello World - Worker Using Durable Objects with Assets",
8
8
  description:
9
- "For full-stack applications requiring static assets, an API, and real-time coordination",
9
+ "Get started with a basic stateful app to build projects like real-time chats, collaborative apps, and multiplayer games, which hosts assets",
10
10
  platform: "workers",
11
11
  copyFiles: {
12
12
  variants: {
@@ -1,9 +1,10 @@
1
1
  export default {
2
2
  configVersion: 1,
3
3
  id: "hello-world-with-assets",
4
- path: "templates/hello-world-with-assets",
5
- displayName: "Worker + Assets",
6
- description: "For static sites with an API or server-side rendering (SSR)",
4
+ path: "templates-experimental/hello-world-with-assets",
5
+ displayName: "Hello World - Worker with Assets",
6
+ description:
7
+ "Get started with a basic Worker that also serves static assets, in the language of your choice",
7
8
  platform: "workers",
8
9
  copyFiles: {
9
10
  variants: {
@@ -3,7 +3,7 @@ import { brandColor, dim } from "@cloudflare/cli/colors";
3
3
  import { runFrameworkGenerator } from "frameworks/index";
4
4
  import { detectPackageManager } from "helpers/packageManagers";
5
5
  import { installPackages } from "helpers/packages";
6
- import type { TemplateConfig } from "../../../src/templates";
6
+ import type { TemplateConfig } from "../../src/templates";
7
7
  import type { C3Context } from "types";
8
8
 
9
9
  const { npm } = detectPackageManager();
@@ -35,7 +35,7 @@ const config: TemplateConfig = {
35
35
  copyFiles: {
36
36
  path: "./templates",
37
37
  },
38
- path: "templates/remix/workers",
38
+ path: "templates-experimental/remix",
39
39
  generate,
40
40
  configure,
41
41
  transformPackageJson: async () => ({
@@ -1,98 +0,0 @@
1
- import { logRaw, updateStatus } from "@cloudflare/cli";
2
- import { blue, brandColor, dim } from "@cloudflare/cli/colors";
3
- import { runFrameworkGenerator } from "frameworks/index";
4
- import { transformFile } from "helpers/codemod";
5
- import { runCommand } from "helpers/command";
6
- import { usesTypescript } from "helpers/files";
7
- import { detectPackageManager } from "helpers/packageManagers";
8
- import * as recast from "recast";
9
- import type { TemplateConfig } from "../../../src/templates";
10
- import type { C3Context, PackageJson } from "types";
11
-
12
- const { npx } = detectPackageManager();
13
-
14
- const generate = async (ctx: C3Context) => {
15
- await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
16
-
17
- logRaw(""); // newline
18
- };
19
-
20
- const configure = async () => {
21
- await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
22
- silent: true,
23
- startText: "Installing adapter",
24
- doneText: `${brandColor("installed")} ${dim(
25
- `via \`${npx} astro add cloudflare\``,
26
- )}`,
27
- });
28
-
29
- updateAstroConfig();
30
- };
31
-
32
- const updateAstroConfig = () => {
33
- const filePath = "astro.config.mjs";
34
-
35
- updateStatus(`Updating configuration in ${blue(filePath)}`);
36
-
37
- transformFile(filePath, {
38
- visitCallExpression: function (n) {
39
- const callee = n.node.callee as recast.types.namedTypes.Identifier;
40
- if (callee.name !== "cloudflare") {
41
- return this.traverse(n);
42
- }
43
-
44
- const b = recast.types.builders;
45
- n.node.arguments = [
46
- b.objectExpression([
47
- b.objectProperty(
48
- b.identifier("platformProxy"),
49
- b.objectExpression([
50
- b.objectProperty(b.identifier("enabled"), b.booleanLiteral(true)),
51
- ]),
52
- ),
53
- ]),
54
- ];
55
-
56
- return false;
57
- },
58
- });
59
- };
60
-
61
- const config: TemplateConfig = {
62
- configVersion: 1,
63
- id: "astro",
64
- frameworkCli: "create-astro",
65
- platform: "pages",
66
- displayName: "Astro",
67
- path: "templates/astro/pages",
68
- copyFiles: {
69
- async selectVariant(ctx) {
70
- // Note: this `selectVariant` function should not be needed
71
- // this is just a quick workaround until
72
- // https://github.com/cloudflare/workers-sdk/issues/7495
73
- // is resolved
74
- return usesTypescript(ctx) ? "ts" : "js";
75
- },
76
- variants: {
77
- js: {
78
- path: "./templates/js",
79
- },
80
- ts: {
81
- path: "./templates/ts",
82
- },
83
- },
84
- },
85
- devScript: "dev",
86
- deployScript: "deploy",
87
- previewScript: "preview",
88
- generate,
89
- configure,
90
- transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
91
- scripts: {
92
- deploy: `astro build && wrangler pages deploy`,
93
- preview: `astro build && wrangler pages dev`,
94
- ...(usesTypescript(ctx) && { "cf-typegen": `wrangler types` }),
95
- },
96
- }),
97
- };
98
- export default config;
@@ -1,2 +0,0 @@
1
- _worker.js
2
- _routes.json
@@ -1,2 +0,0 @@
1
- _worker.js
2
- _routes.json
@@ -1,68 +0,0 @@
1
- import { logRaw } from "@cloudflare/cli";
2
- import { brandColor, dim } from "@cloudflare/cli/colors";
3
- import { spinner } from "@cloudflare/cli/interactive";
4
- import { runFrameworkGenerator } from "frameworks/index";
5
- import { transformFile } from "helpers/codemod";
6
- import { detectPackageManager } from "helpers/packageManagers";
7
- import type { TemplateConfig } from "../../../src/templates";
8
- import type { C3Context } from "types";
9
-
10
- const { npm } = detectPackageManager();
11
-
12
- const generate = async (ctx: C3Context) => {
13
- await runFrameworkGenerator(ctx, [
14
- ctx.project.name,
15
- "--template",
16
- "https://github.com/remix-run/remix/tree/main/templates/cloudflare",
17
- ]);
18
-
19
- logRaw(""); // newline
20
- };
21
-
22
- const configure = async () => {
23
- const typeDefsPath = "load-context.ts";
24
-
25
- const s = spinner();
26
- s.start(`Updating \`${typeDefsPath}\``);
27
-
28
- // Remove the empty Env declaration from the template to allow the type from
29
- // worker-configuration.d.ts to take over
30
- transformFile(typeDefsPath, {
31
- visitTSInterfaceDeclaration(n) {
32
- if (n.node.id.type === "Identifier" && n.node.id.name !== "Env") {
33
- return this.traverse(n);
34
- }
35
-
36
- // Removes the node
37
- n.replace();
38
- return false;
39
- },
40
- });
41
-
42
- s.stop(`${brandColor("updated")} \`${dim(typeDefsPath)}\``);
43
- };
44
-
45
- const config: TemplateConfig = {
46
- configVersion: 1,
47
- id: "remix",
48
- frameworkCli: "create-remix",
49
- platform: "pages",
50
- displayName: "Remix",
51
- copyFiles: {
52
- path: "./templates",
53
- },
54
- path: "templates/remix/pages",
55
- generate,
56
- configure,
57
- transformPackageJson: async () => ({
58
- scripts: {
59
- deploy: `${npm} run build && wrangler pages deploy`,
60
- preview: `${npm} run build && wrangler pages dev`,
61
- "cf-typegen": `wrangler types`,
62
- },
63
- }),
64
- devScript: "dev",
65
- deployScript: "deploy",
66
- previewScript: "preview",
67
- };
68
- export default config;