create-cloudflare 0.0.0-62d5471ea → 0.0.0-62df08af3

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 (95) hide show
  1. package/dist/cli.js +934 -855
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +5 -5
  4. package/templates/angular/pages/c3.ts +1 -0
  5. package/templates/astro/pages/c3.ts +1 -0
  6. package/templates/astro/workers/templates/ts/wrangler.jsonc +1 -1
  7. package/templates/common/c3.ts +5 -1
  8. package/templates/docusaurus/pages/c3.ts +1 -0
  9. package/templates/gatsby/pages/c3.ts +1 -0
  10. package/templates/hello-world/ts/test/env.d.ts +3 -0
  11. package/templates/hello-world/ts/worker-configuration.d.ts +6 -2
  12. package/templates/hello-world-durable-object/c3.ts +4 -1
  13. package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +6 -4
  14. package/templates/hello-world-durable-object-with-assets/js/src/index.js +11 -10
  15. package/templates/hello-world-durable-object-with-assets/js/wrangler.jsonc +2 -2
  16. package/templates/hello-world-durable-object-with-assets/ts/src/index.ts +10 -9
  17. package/templates/hello-world-durable-object-with-assets/ts/worker-configuration.d.ts +7 -4
  18. package/templates/hello-world-durable-object-with-assets/ts/wrangler.jsonc +1 -1
  19. package/templates/hello-world-with-assets/c3.ts +4 -1
  20. package/templates/hello-world-with-assets/js/public/index.html +2 -2
  21. package/templates/hello-world-with-assets/py/public/index.html +2 -2
  22. package/templates/hello-world-with-assets/ts/public/index.html +2 -2
  23. package/templates/hello-world-with-assets/ts/test/env.d.ts +3 -0
  24. package/templates/hello-world-with-assets/ts/test/tsconfig.json +1 -1
  25. package/templates/hello-world-with-assets/ts/worker-configuration.d.ts +6 -3
  26. package/templates/hono/c3.ts +5 -66
  27. package/templates/hono/pages/c3.ts +44 -0
  28. package/templates/hono/pages/templates/src/index.tsx +12 -0
  29. package/templates/hono/{templates → pages/templates}/wrangler.jsonc +1 -1
  30. package/{templates-experimental/hono → templates/hono/workers}/c3.ts +2 -4
  31. package/templates/next/c3.ts +7 -221
  32. package/templates/next/pages/c3.ts +225 -0
  33. package/{templates-experimental/next → templates/next/workers}/c3.ts +6 -7
  34. package/templates/next/workers/templates/open-next.config.ts +6 -0
  35. package/{templates-experimental/next → templates/next/workers}/templates/wrangler.jsonc +1 -1
  36. package/templates/nuxt/pages/c3.ts +2 -0
  37. package/templates/nuxt/workers/c3.ts +1 -0
  38. package/templates/openapi/c3.ts +5 -1
  39. package/templates/pre-existing/c3.ts +5 -1
  40. package/templates/queues/c3.ts +5 -1
  41. package/templates/qwik/c3.ts +5 -144
  42. package/templates/qwik/pages/c3.ts +150 -0
  43. package/{templates-experimental/qwik → templates/qwik/workers}/c3.ts +2 -2
  44. package/templates/react/pages/c3.ts +1 -0
  45. package/templates/react/workers/js/src/App.jsx +1 -1
  46. package/templates/react/workers/js/{api → worker}/index.js +1 -1
  47. package/templates/react/workers/js/wrangler.jsonc +2 -2
  48. package/templates/react/workers/ts/src/App.tsx +1 -1
  49. package/templates/react/workers/ts/tsconfig.worker.json +1 -1
  50. package/templates/react/workers/ts/{api → worker}/index.ts +2 -3
  51. package/templates/react/workers/ts/wrangler.jsonc +2 -2
  52. package/templates/react-router/c3.ts +53 -0
  53. package/templates/react-router/templates/worker-configuration.d.ts +8 -0
  54. package/templates/remix/c3.ts +1 -0
  55. package/templates/remix/pages/c3.ts +1 -0
  56. package/templates/scheduled/c3.ts +5 -1
  57. package/templates/scheduled/ts/src/index.ts +7 -0
  58. package/templates/svelte/c3.ts +5 -154
  59. package/templates/svelte/pages/c3.ts +160 -0
  60. package/{templates-experimental/svelte → templates/svelte/workers}/c3.ts +3 -3
  61. package/templates/svelte/workers/templates/static/.assetsignore +2 -0
  62. package/templates/vue/pages/c3.ts +1 -0
  63. package/templates/vue/workers/js/server/index.js +2 -2
  64. package/templates/vue/workers/js/wrangler.jsonc +0 -1
  65. package/templates/vue/workers/ts/server/index.ts +2 -3
  66. package/templates/vue/workers/ts/wrangler.jsonc +0 -1
  67. package/templates/hono/snippets/appDeclaration.ts +0 -1
  68. package/templates-experimental/next/templates/open-next.config.ts +0 -6
  69. package/templates-experimental/svelte/templates/static/.assetsignore +0 -4
  70. /package/{templates-experimental/hono → templates/hono/pages}/templates/worker-configuration.d.ts +0 -0
  71. /package/{templates-experimental/hono → templates/hono/workers}/templates/public/index.html +0 -0
  72. /package/{templates-experimental/hono → templates/hono/workers}/templates/src/index.ts +0 -0
  73. /package/templates/hono/{templates → workers/templates}/worker-configuration.d.ts +0 -0
  74. /package/{templates-experimental/hono → templates/hono/workers}/templates/wrangler.jsonc +0 -0
  75. /package/templates/next/{README.md → pages/README.md} +0 -0
  76. /package/templates/next/{app → pages/app}/js/app/api/hello/route.js +0 -0
  77. /package/templates/next/{app → pages/app}/js/app/not-found.js +0 -0
  78. /package/templates/next/{app → pages/app}/ts/app/api/hello/route.ts +0 -0
  79. /package/templates/next/{app → pages/app}/ts/app/not-found.tsx +0 -0
  80. /package/templates/next/{env.d.ts → pages/env.d.ts} +0 -0
  81. /package/templates/next/pages/{js → pages/js}/pages/api/hello.js +0 -0
  82. /package/templates/next/pages/{ts → pages/ts}/pages/api/hello.ts +0 -0
  83. /package/templates/next/{wrangler.jsonc → pages/wrangler.jsonc} +0 -0
  84. /package/{templates-experimental/next → templates/next/workers}/templates/.dev.vars +0 -0
  85. /package/{templates-experimental/next → templates/next/workers}/templates/__dot__gitignore +0 -0
  86. /package/{templates-experimental/next → templates/next/workers}/templates/cloudflare-env.d.ts +0 -0
  87. /package/{templates-experimental/qwik → templates/qwik/pages}/snippets/getPlatformProxy.ts +0 -0
  88. /package/{templates-experimental/qwik → templates/qwik/pages}/templates/worker-configuration.d.ts +0 -0
  89. /package/templates/qwik/{templates → pages/templates}/wrangler.jsonc +0 -0
  90. /package/templates/qwik/{snippets → workers/snippets}/getPlatformProxy.ts +0 -0
  91. /package/{templates-experimental/qwik → templates/qwik/workers}/templates/public/.assetsignore +0 -0
  92. /package/templates/qwik/{templates → workers/templates}/worker-configuration.d.ts +0 -0
  93. /package/{templates-experimental/qwik → templates/qwik/workers}/templates/wrangler.jsonc +0 -0
  94. /package/templates/svelte/{templates → pages/templates}/wrangler.jsonc +0 -0
  95. /package/{templates-experimental/svelte → templates/svelte/workers}/templates/wrangler.jsonc +0 -0
@@ -1,148 +1,9 @@
1
- import { endSection } from "@cloudflare/cli";
2
- import { brandColor } from "@cloudflare/cli/colors";
3
- import { spinner } from "@cloudflare/cli/interactive";
4
- import { runFrameworkGenerator } from "frameworks/index";
5
- import { loadTemplateSnippets, transformFile } from "helpers/codemod";
6
- import { quoteShellArgs, runCommand } from "helpers/command";
7
- import { usesTypescript } from "helpers/files";
8
- import { detectPackageManager } from "helpers/packageManagers";
9
- import * as recast from "recast";
10
- import type { TemplateConfig } from "../../src/templates";
11
- import type { C3Context } from "types";
1
+ import pages from "./pages/c3";
2
+ import workers from "./workers/c3";
3
+ import type { MultiPlatformTemplateConfig } from "../../src/templates";
12
4
 
13
- const { npm, npx, name } = detectPackageManager();
14
-
15
- const generate = async (ctx: C3Context) => {
16
- await runFrameworkGenerator(ctx, ["playground", ctx.project.name]);
17
- };
18
-
19
- const configure = async (ctx: C3Context) => {
20
- // Add the pages integration
21
- // For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
22
- const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
23
- endSection(`Running ${quoteShellArgs(cmd)}`);
24
- await runCommand(cmd);
25
-
26
- addBindingsProxy(ctx);
27
- populateCloudflareEnv();
28
- };
29
-
30
- const addBindingsProxy = (ctx: C3Context) => {
31
- // Qwik only has a typescript template atm.
32
- // This check is an extra precaution
33
- if (!usesTypescript(ctx)) {
34
- return;
35
- }
36
-
37
- const s = spinner();
38
- s.start("Updating `vite.config.ts`");
39
-
40
- const snippets = loadTemplateSnippets(ctx);
41
- const b = recast.types.builders;
42
-
43
- transformFile("vite.config.ts", {
44
- // Insert the env declaration after the last import (but before the rest of the body)
45
- visitProgram: function (n) {
46
- const lastImportIndex = n.node.body.findLastIndex(
47
- (t) => t.type === "ImportDeclaration",
48
- );
49
- const lastImport = n.get("body", lastImportIndex);
50
- lastImport.insertAfter(...snippets.getPlatformProxyTs);
51
-
52
- return this.traverse(n);
53
- },
54
- // Pass the `platform` object from the declaration to the `qwikCity` plugin
55
- visitCallExpression: function (n) {
56
- const callee = n.node.callee as recast.types.namedTypes.Identifier;
57
- if (callee.name !== "qwikCity") {
58
- return this.traverse(n);
59
- }
60
-
61
- // The config object passed to `qwikCity`
62
- const configArgument = n.node.arguments[0] as
63
- | recast.types.namedTypes.ObjectExpression
64
- | undefined;
65
-
66
- const platformPropery = b.objectProperty.from({
67
- key: b.identifier("platform"),
68
- value: b.identifier("platform"),
69
- shorthand: true,
70
- });
71
-
72
- if (!configArgument) {
73
- n.node.arguments = [b.objectExpression([platformPropery])];
74
-
75
- return false;
76
- }
77
-
78
- if (configArgument.type !== "ObjectExpression") {
79
- throw new Error("Failed to update `vite.config.ts`");
80
- }
81
-
82
- // Add the `platform` object to the object
83
- configArgument.properties.push(platformPropery);
84
-
85
- return false;
86
- },
87
- });
88
-
89
- s.stop(`${brandColor("updated")} \`vite.config.ts\``);
90
- };
91
-
92
- const populateCloudflareEnv = () => {
93
- const entrypointPath = "src/entry.cloudflare-pages.tsx";
94
-
95
- const s = spinner();
96
- s.start(`Updating \`${entrypointPath}\``);
97
-
98
- transformFile(entrypointPath, {
99
- visitTSInterfaceDeclaration: function (n) {
100
- const b = recast.types.builders;
101
- const id = n.node.id as recast.types.namedTypes.Identifier;
102
- if (id.name !== "QwikCityPlatform") {
103
- this.traverse(n);
104
- }
105
-
106
- const newBody = [
107
- ["env", "Env"],
108
- // Qwik doesn't supply `cf` to the platform object. Should they do so, uncomment this
109
- // ["cf", "CfProperties"],
110
- ].map(([varName, type]) =>
111
- b.tsPropertySignature(
112
- b.identifier(varName),
113
- b.tsTypeAnnotation(b.tsTypeReference(b.identifier(type))),
114
- ),
115
- );
116
-
117
- n.node.body.body = newBody;
118
-
119
- return false;
120
- },
121
- });
122
-
123
- s.stop(`${brandColor("updated")} \`${entrypointPath}\``);
124
- };
125
-
126
- const config: TemplateConfig = {
127
- configVersion: 1,
128
- id: "qwik",
129
- frameworkCli: "create-qwik",
5
+ const config: MultiPlatformTemplateConfig = {
130
6
  displayName: "Qwik",
131
- platform: "pages",
132
- copyFiles: {
133
- path: "./templates",
134
- },
135
- generate,
136
- configure,
137
- transformPackageJson: async () => ({
138
- scripts: {
139
- deploy: `${npm} run build && wrangler pages deploy`,
140
- preview: `${npm} run build && wrangler pages dev`,
141
- "cf-typegen": `wrangler types`,
142
- },
143
- }),
144
- devScript: "dev",
145
- deployScript: "deploy",
146
- previewScript: "preview",
7
+ platformVariants: { pages, workers },
147
8
  };
148
9
  export default config;
@@ -0,0 +1,150 @@
1
+ import { endSection } from "@cloudflare/cli";
2
+ import { brandColor } from "@cloudflare/cli/colors";
3
+ import { spinner } from "@cloudflare/cli/interactive";
4
+ import { runFrameworkGenerator } from "frameworks/index";
5
+ import { loadTemplateSnippets, transformFile } from "helpers/codemod";
6
+ import { quoteShellArgs, runCommand } from "helpers/command";
7
+ import { usesTypescript } from "helpers/files";
8
+ import { detectPackageManager } from "helpers/packageManagers";
9
+ import * as recast from "recast";
10
+ import type { TemplateConfig } from "../../../src/templates";
11
+ import type { C3Context } from "types";
12
+
13
+ const { npm, npx, name } = detectPackageManager();
14
+
15
+ const generate = async (ctx: C3Context) => {
16
+ await runFrameworkGenerator(ctx, ["playground", ctx.project.name]);
17
+ };
18
+
19
+ const configure = async (ctx: C3Context) => {
20
+ // Add the pages integration
21
+ // For some reason `pnpx qwik add` fails for qwik so we use `pnpm qwik add` instead.
22
+ const cmd = [name === "pnpm" ? npm : npx, "qwik", "add", "cloudflare-pages"];
23
+ endSection(`Running ${quoteShellArgs(cmd)}`);
24
+ await runCommand(cmd);
25
+
26
+ addBindingsProxy(ctx);
27
+ populateCloudflareEnv();
28
+ };
29
+
30
+ const addBindingsProxy = (ctx: C3Context) => {
31
+ // Qwik only has a typescript template atm.
32
+ // This check is an extra precaution
33
+ if (!usesTypescript(ctx)) {
34
+ return;
35
+ }
36
+
37
+ const s = spinner();
38
+ s.start("Updating `vite.config.ts`");
39
+
40
+ const snippets = loadTemplateSnippets(ctx);
41
+ const b = recast.types.builders;
42
+
43
+ transformFile("vite.config.ts", {
44
+ // Insert the env declaration after the last import (but before the rest of the body)
45
+ visitProgram: function (n) {
46
+ const lastImportIndex = n.node.body.findLastIndex(
47
+ (t) => t.type === "ImportDeclaration",
48
+ );
49
+ const lastImport = n.get("body", lastImportIndex);
50
+ lastImport.insertAfter(...snippets.getPlatformProxyTs);
51
+
52
+ return this.traverse(n);
53
+ },
54
+ // Pass the `platform` object from the declaration to the `qwikCity` plugin
55
+ visitCallExpression: function (n) {
56
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
57
+ if (callee.name !== "qwikCity") {
58
+ return this.traverse(n);
59
+ }
60
+
61
+ // The config object passed to `qwikCity`
62
+ const configArgument = n.node.arguments[0] as
63
+ | recast.types.namedTypes.ObjectExpression
64
+ | undefined;
65
+
66
+ const platformPropery = b.objectProperty.from({
67
+ key: b.identifier("platform"),
68
+ value: b.identifier("platform"),
69
+ shorthand: true,
70
+ });
71
+
72
+ if (!configArgument) {
73
+ n.node.arguments = [b.objectExpression([platformPropery])];
74
+
75
+ return false;
76
+ }
77
+
78
+ if (configArgument.type !== "ObjectExpression") {
79
+ throw new Error("Failed to update `vite.config.ts`");
80
+ }
81
+
82
+ // Add the `platform` object to the object
83
+ configArgument.properties.push(platformPropery);
84
+
85
+ return false;
86
+ },
87
+ });
88
+
89
+ s.stop(`${brandColor("updated")} \`vite.config.ts\``);
90
+ };
91
+
92
+ const populateCloudflareEnv = () => {
93
+ const entrypointPath = "src/entry.cloudflare-pages.tsx";
94
+
95
+ const s = spinner();
96
+ s.start(`Updating \`${entrypointPath}\``);
97
+
98
+ transformFile(entrypointPath, {
99
+ visitTSInterfaceDeclaration: function (n) {
100
+ const b = recast.types.builders;
101
+ const id = n.node.id as recast.types.namedTypes.Identifier;
102
+ if (id.name !== "QwikCityPlatform") {
103
+ this.traverse(n);
104
+ }
105
+
106
+ const newBody = [
107
+ ["env", "Env"],
108
+ // Qwik doesn't supply `cf` to the platform object. Should they do so, uncomment this
109
+ // ["cf", "CfProperties"],
110
+ ].map(([varName, type]) =>
111
+ b.tsPropertySignature(
112
+ b.identifier(varName),
113
+ b.tsTypeAnnotation(b.tsTypeReference(b.identifier(type))),
114
+ ),
115
+ );
116
+
117
+ n.node.body.body = newBody;
118
+
119
+ return false;
120
+ },
121
+ });
122
+
123
+ s.stop(`${brandColor("updated")} \`${entrypointPath}\``);
124
+ };
125
+
126
+ const config: TemplateConfig = {
127
+ configVersion: 1,
128
+ id: "qwik",
129
+ frameworkCli: "create-qwik",
130
+ displayName: "Qwik",
131
+ platform: "pages",
132
+ hidden: true,
133
+ copyFiles: {
134
+ path: "./templates",
135
+ },
136
+ path: "templates/qwik/pages",
137
+ generate,
138
+ configure,
139
+ transformPackageJson: async () => ({
140
+ scripts: {
141
+ deploy: `${npm} run build && wrangler pages deploy`,
142
+ preview: `${npm} run build && wrangler pages dev`,
143
+ "cf-typegen": `wrangler types`,
144
+ },
145
+ }),
146
+ devScript: "dev",
147
+ deployScript: "deploy",
148
+ previewScript: "preview",
149
+ };
150
+ export default config;
@@ -7,7 +7,7 @@ import { quoteShellArgs, runCommand } from "helpers/command";
7
7
  import { removeFile, usesTypescript } from "helpers/files";
8
8
  import { detectPackageManager } from "helpers/packageManagers";
9
9
  import * as recast from "recast";
10
- import type { TemplateConfig } from "../../src/templates";
10
+ import type { TemplateConfig } from "../../../src/templates";
11
11
  import type { C3Context } from "types";
12
12
 
13
13
  const { npm, npx, name } = detectPackageManager();
@@ -137,7 +137,7 @@ const config: TemplateConfig = {
137
137
  copyFiles: {
138
138
  path: "./templates",
139
139
  },
140
- path: "templates-experimental/qwik",
140
+ path: "templates/qwik/workers",
141
141
  generate,
142
142
  configure,
143
143
  transformPackageJson: async () => ({
@@ -47,6 +47,7 @@ const config: TemplateConfig = {
47
47
  frameworkCli: "create-vite",
48
48
  displayName: "React",
49
49
  platform: "pages",
50
+ hidden: true,
50
51
  path: "templates/react/pages",
51
52
  generate,
52
53
  transformPackageJson: async () => ({
@@ -45,7 +45,7 @@ function App() {
45
45
  Name from API is: {name}
46
46
  </button>
47
47
  <p>
48
- Edit <code>api/index.js</code> to change the name
48
+ Edit <code>worker/index.js</code> to change the name
49
49
  </p>
50
50
  </div>
51
51
  <p className='read-the-docs'>
@@ -8,6 +8,6 @@ export default {
8
8
  });
9
9
  }
10
10
 
11
- return env.ASSETS.fetch(request);
11
+ return new Response(null, { status: 404 });
12
12
  },
13
13
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "<TBD>",
3
- "main": "api/index.js",
3
+ "main": "worker/index.js",
4
4
  "compatibility_date": "<TBD>",
5
- "assets": { "not_found_handling": "single-page-application", "binding": "ASSETS" },
5
+ "assets": { "not_found_handling": "single-page-application" },
6
6
  "observability": {
7
7
  "enabled": true
8
8
  }
@@ -45,7 +45,7 @@ function App() {
45
45
  Name from API is: {name}
46
46
  </button>
47
47
  <p>
48
- Edit <code>api/index.ts</code> to change the name
48
+ Edit <code>worker/index.ts</code> to change the name
49
49
  </p>
50
50
  </div>
51
51
  <p className='read-the-docs'>
@@ -4,5 +4,5 @@
4
4
  "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.worker.tsbuildinfo",
5
5
  "types": ["@cloudflare/workers-types/2023-07-01", "./worker-configuration.d.ts", "vite/client"],
6
6
  },
7
- "include": ["api"],
7
+ "include": ["worker"],
8
8
  }
@@ -1,5 +1,5 @@
1
1
  export default {
2
- fetch(request, env) {
2
+ fetch(request) {
3
3
  const url = new URL(request.url);
4
4
 
5
5
  if (url.pathname.startsWith("/api/")) {
@@ -7,7 +7,6 @@ export default {
7
7
  name: "Cloudflare",
8
8
  });
9
9
  }
10
-
11
- return env.ASSETS.fetch(request);
10
+ return new Response(null, { status: 404 });
12
11
  },
13
12
  } satisfies ExportedHandler<Env>;
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "<TBD>",
3
- "main": "api/index.ts",
3
+ "main": "worker/index.ts",
4
4
  "compatibility_date": "<TBD>",
5
- "assets": { "not_found_handling": "single-page-application", "binding": "ASSETS" },
5
+ "assets": { "not_found_handling": "single-page-application" },
6
6
  "observability": {
7
7
  "enabled": true
8
8
  }
@@ -0,0 +1,53 @@
1
+ import { logRaw } from "@cloudflare/cli";
2
+ import { runFrameworkGenerator } from "frameworks/index";
3
+ import { detectPackageManager } from "helpers/packageManagers";
4
+ import type { TemplateConfig } from "../../src/templates";
5
+ import type { C3Context } from "types";
6
+
7
+ const { npm } = detectPackageManager();
8
+
9
+ const generate = async (ctx: C3Context) => {
10
+ await runFrameworkGenerator(ctx, [
11
+ ctx.project.name,
12
+ "--template",
13
+ "https://github.com/remix-run/react-router-templates/tree/main/cloudflare",
14
+ // to prevent asking about git twice, just let c3 do it
15
+ "--no-git-init",
16
+ "--no-install",
17
+ ]);
18
+
19
+ logRaw(""); // newline
20
+ };
21
+
22
+ // TODO: Uncomment this once @react-router/dev updates its peer dependency to Wrangler v4
23
+ // const configure = async () => {
24
+ // await installPackages(["wrangler@latest"], {
25
+ // dev: true,
26
+ // startText: "Updating the Wrangler version",
27
+ // doneText: `${brandColor(`updated`)} ${dim("wrangler@latest")}`,
28
+ // });
29
+ // };
30
+
31
+ const config: TemplateConfig = {
32
+ configVersion: 1,
33
+ id: "react-router",
34
+ platform: "workers",
35
+ frameworkCli: "create-react-router",
36
+ displayName: "React Router (formerly Remix)",
37
+ copyFiles: {
38
+ path: "./templates",
39
+ },
40
+ generate,
41
+ // configure,
42
+ transformPackageJson: async () => ({
43
+ scripts: {
44
+ deploy: `${npm} run build && wrangler deploy`,
45
+ preview: `${npm} run build && vite preview`,
46
+ "cf-typegen": `wrangler types`,
47
+ },
48
+ }),
49
+ devScript: "dev",
50
+ deployScript: "deploy",
51
+ previewScript: "preview",
52
+ };
53
+ export default config;
@@ -0,0 +1,8 @@
1
+ // Generated by Wrangler
2
+ // After adding bindings to `wrangler.jsonc`, regenerate this interface via `npm run cf-typegen`
3
+ declare namespace Cloudflare {
4
+ interface Env {
5
+ VALUE_FROM_CLOUDFLARE: "Hello from Cloudflare";
6
+ }
7
+ }
8
+ interface Env extends Cloudflare.Env {}
@@ -5,5 +5,6 @@ import type { MultiPlatformTemplateConfig } from "../../src/templates";
5
5
  const config: MultiPlatformTemplateConfig = {
6
6
  displayName: "Remix",
7
7
  platformVariants: { pages, workers },
8
+ hidden: true,
8
9
  };
9
10
  export default config;
@@ -47,6 +47,7 @@ const config: TemplateConfig = {
47
47
  id: "remix",
48
48
  frameworkCli: "create-remix",
49
49
  platform: "pages",
50
+ hidden: true,
50
51
  displayName: "Remix",
51
52
  copyFiles: {
52
53
  path: "./templates",
@@ -1,4 +1,6 @@
1
- export default {
1
+ import type { TemplateConfig } from "../../src/templates";
2
+
3
+ const config: TemplateConfig = {
2
4
  configVersion: 1,
3
5
  id: "scheduled",
4
6
  displayName: "Scheduled Worker (Cron Trigger)",
@@ -16,3 +18,5 @@ export default {
16
18
  },
17
19
  },
18
20
  };
21
+
22
+ export default config;
@@ -16,6 +16,13 @@
16
16
  */
17
17
 
18
18
  export default {
19
+ async fetch(req) {
20
+ const url = new URL(req.url);
21
+ url.pathname = '/__scheduled';
22
+ url.searchParams.append('cron', '* * * * *');
23
+ return new Response(`To test the scheduled handler, ensure you have used the "--test-scheduled" then try running "curl ${url.href}".`);
24
+ },
25
+
19
26
  // The scheduled handler is invoked at the interval set in our wrangler.jsonc's
20
27
  // [[triggers]] configuration.
21
28
  async scheduled(event, env, ctx): Promise<void> {
@@ -1,158 +1,9 @@
1
- import { existsSync } from "node:fs";
2
- import { platform } from "node:os";
3
- import { logRaw, updateStatus } from "@cloudflare/cli";
4
- import { blue, brandColor, dim } from "@cloudflare/cli/colors";
5
- import { runFrameworkGenerator } from "frameworks/index";
6
- import { transformFile } from "helpers/codemod";
7
- import { usesTypescript } from "helpers/files";
8
- import { detectPackageManager } from "helpers/packageManagers";
9
- import { installPackages } from "helpers/packages";
10
- import * as recast from "recast";
11
- import type { TemplateConfig } from "../../src/templates";
12
- import type { C3Context, PackageJson } from "types";
1
+ import pages from "./pages/c3";
2
+ import workers from "./workers/c3";
3
+ import type { MultiPlatformTemplateConfig } from "../../src/templates";
13
4
 
14
- const { npm } = detectPackageManager();
15
-
16
- const generate = async (ctx: C3Context) => {
17
- await runFrameworkGenerator(ctx, ["create", ctx.project.name]);
18
-
19
- logRaw("");
20
- };
21
-
22
- const configure = async (ctx: C3Context) => {
23
- // Install the adapter
24
- const pkg = `@sveltejs/adapter-cloudflare`;
25
- await installPackages([pkg], {
26
- dev: true,
27
- startText: "Adding the Cloudflare Pages adapter",
28
- doneText: `${brandColor(`installed`)} ${dim(pkg)}`,
29
- });
30
-
31
- updateSvelteConfig();
32
- updatePlaywrightConfig(usesTypescript(ctx));
33
- updateTypeDefinitions(ctx);
34
- };
35
-
36
- const updateSvelteConfig = () => {
37
- // All we need to do is change the import statement in svelte.config.js
38
- updateStatus(`Changing adapter in ${blue("svelte.config.js")}`);
39
-
40
- transformFile("svelte.config.js", {
41
- visitImportDeclaration: function (n) {
42
- // importSource is the `x` in `import y from "x"`
43
- const importSource = n.value.source;
44
- if (importSource.value === "@sveltejs/adapter-auto") {
45
- importSource.value = "@sveltejs/adapter-cloudflare";
46
- }
47
-
48
- // stop traversing this node
49
- return false;
50
- },
51
- });
52
- };
53
-
54
- const updatePlaywrightConfig = (shouldUseTypescript: boolean) => {
55
- const filePath = `playwright.config.${shouldUseTypescript ? "ts" : "js"}`;
56
- if (!existsSync(filePath)) {
57
- return;
58
- }
59
-
60
- updateStatus(`Changing webServer port in ${blue(filePath)}`);
61
-
62
- transformFile(filePath, {
63
- visitObjectExpression: function (n) {
64
- const portProp = n.node.properties.find((prop) => {
65
- if (!("key" in prop) || !("name" in prop.key)) {
66
- return false;
67
- }
68
-
69
- return prop.key.name === "port";
70
- });
71
-
72
- if (!portProp || !("value" in portProp) || !("value" in portProp.value)) {
73
- return this.traverse(n);
74
- }
75
-
76
- portProp.value.value = 8788;
77
- return false;
78
- },
79
- });
80
- };
81
-
82
- const updateTypeDefinitions = (ctx: C3Context) => {
83
- if (!usesTypescript(ctx)) {
84
- return;
85
- }
86
-
87
- updateStatus(`Updating global type definitions in ${blue("app.d.ts")}`);
88
-
89
- const b = recast.types.builders;
90
-
91
- transformFile("src/app.d.ts", {
92
- visitTSModuleDeclaration(n) {
93
- if (n.value.id.name === "App" && n.node.body) {
94
- const moduleBlock = n.node
95
- .body as recast.types.namedTypes.TSModuleBlock;
96
-
97
- const platformInterface = b.tsInterfaceDeclaration(
98
- b.identifier("Platform"),
99
- b.tsInterfaceBody([
100
- b.tsPropertySignature(
101
- b.identifier("env"),
102
- b.tsTypeAnnotation(b.tsTypeReference(b.identifier("Env"))),
103
- ),
104
- b.tsPropertySignature(
105
- b.identifier("cf"),
106
- b.tsTypeAnnotation(
107
- b.tsTypeReference(b.identifier("CfProperties")),
108
- ),
109
- ),
110
- b.tsPropertySignature(
111
- b.identifier("ctx"),
112
- b.tsTypeAnnotation(
113
- b.tsTypeReference(b.identifier("ExecutionContext")),
114
- ),
115
- ),
116
- ]),
117
- );
118
-
119
- moduleBlock.body.unshift(platformInterface);
120
- }
121
-
122
- this.traverse(n);
123
- },
124
- });
125
- };
126
-
127
- const config: TemplateConfig = {
128
- configVersion: 1,
129
- id: "svelte",
130
- frameworkCli: "sv",
5
+ const config: MultiPlatformTemplateConfig = {
131
6
  displayName: "SvelteKit",
132
- platform: "pages",
133
- copyFiles: {
134
- path: "./templates",
135
- },
136
- generate,
137
- configure,
138
- transformPackageJson: async (original: PackageJson, ctx: C3Context) => {
139
- let scripts: Record<string, string> = {
140
- preview: `${npm} run build && wrangler pages dev`,
141
- deploy: `${npm} run build && wrangler pages deploy`,
142
- };
143
-
144
- if (usesTypescript(ctx)) {
145
- const mv = platform() === "win32" ? "move" : "mv";
146
- scripts = {
147
- ...scripts,
148
- "cf-typegen": `wrangler types && ${mv} worker-configuration.d.ts src/`,
149
- };
150
- }
151
-
152
- return { scripts };
153
- },
154
- devScript: "dev",
155
- deployScript: "deploy",
156
- previewScript: "preview",
7
+ platformVariants: { pages, workers },
157
8
  };
158
9
  export default config;