create-cloudflare 0.0.0-e7ccc859 → 0.0.0-e7f8dc32

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 (80) hide show
  1. package/dist/cli.js +26913 -24870
  2. package/package.json +8 -4
  3. package/templates/angular/c3.ts +10 -9
  4. package/templates/astro/c3.ts +81 -19
  5. package/templates/astro/snippets/runtimeDeclaration.ts +5 -0
  6. package/templates/astro/templates/wrangler.toml +52 -0
  7. package/templates/common/c3.ts +7 -5
  8. package/templates/common/js/.editorconfig +0 -1
  9. package/templates/common/js/wrangler.toml +68 -22
  10. package/templates/common/ts/.editorconfig +0 -1
  11. package/templates/common/ts/wrangler.toml +68 -22
  12. package/templates/docusaurus/c3.ts +5 -6
  13. package/templates/gatsby/c3.ts +7 -5
  14. package/templates/hello-world/c3.ts +7 -5
  15. package/templates/hello-world/js/.editorconfig +0 -1
  16. package/templates/hello-world/js/package.json +3 -1
  17. package/templates/hello-world/js/test/index.spec.js +20 -0
  18. package/templates/hello-world/js/vitest.config.js +11 -0
  19. package/templates/hello-world/js/wrangler.toml +69 -22
  20. package/templates/hello-world/ts/.editorconfig +0 -1
  21. package/templates/hello-world/ts/package.json +5 -2
  22. package/templates/hello-world/ts/test/index.spec.ts +25 -0
  23. package/templates/hello-world/ts/test/tsconfig.json +11 -0
  24. package/templates/hello-world/ts/tsconfig.json +3 -2
  25. package/templates/hello-world/ts/vitest.config.ts +11 -0
  26. package/templates/hello-world/ts/wrangler.toml +69 -22
  27. package/templates/hello-world-durable-object/c3.ts +7 -5
  28. package/templates/hello-world-durable-object/js/.editorconfig +0 -1
  29. package/templates/hello-world-durable-object/js/wrangler.toml +69 -23
  30. package/templates/hello-world-durable-object/ts/.editorconfig +0 -1
  31. package/templates/hello-world-durable-object/ts/wrangler.toml +68 -21
  32. package/templates/hello-world-python/c3.ts +9 -0
  33. package/templates/hello-world-python/py/__dot__gitignore +68 -0
  34. package/templates/hello-world-python/py/package.json +13 -0
  35. package/templates/hello-world-python/py/src/entry.py +4 -0
  36. package/templates/hello-world-python/py/wrangler.toml +4 -0
  37. package/templates/hono/c3.ts +1 -1
  38. package/templates/next/README.md +68 -0
  39. package/templates/next/app/js/app/api/hello/route.js +21 -0
  40. package/templates/next/app/js/app/not-found.js +58 -0
  41. package/templates/next/app/ts/app/api/hello/route.ts +22 -0
  42. package/templates/next/app/ts/app/not-found.tsx +58 -0
  43. package/templates/next/c3.ts +99 -76
  44. package/templates/next/env.d.ts +5 -0
  45. package/templates/next/pages/js/pages/api/hello.js +23 -0
  46. package/templates/next/pages/ts/pages/api/hello.ts +24 -0
  47. package/templates/next/wrangler.toml +54 -0
  48. package/templates/nuxt/c3.ts +94 -19
  49. package/templates/nuxt/templates/env.d.ts +14 -0
  50. package/templates/nuxt/templates/worker-configuration.d.ts +4 -0
  51. package/templates/nuxt/templates/wrangler.toml +52 -0
  52. package/templates/pre-existing/c3.ts +2 -2
  53. package/templates/pre-existing/js/.editorconfig +0 -1
  54. package/templates/queues/c3.ts +7 -5
  55. package/templates/queues/js/.editorconfig +0 -1
  56. package/templates/queues/js/wrangler.toml +85 -2
  57. package/templates/queues/ts/.editorconfig +0 -1
  58. package/templates/queues/ts/wrangler.toml +85 -2
  59. package/templates/qwik/c3.ts +82 -28
  60. package/templates/qwik/snippets/getPlatformProxy.ts +6 -0
  61. package/templates/qwik/templates/worker-configuration.d.ts +4 -0
  62. package/templates/qwik/templates/wrangler.toml +52 -0
  63. package/templates/react/c3.ts +7 -5
  64. package/templates/remix/c3.ts +39 -6
  65. package/templates/remix/templates/worker-configuration.d.ts +4 -0
  66. package/templates/remix/templates/wrangler.toml +52 -0
  67. package/templates/scheduled/c3.ts +7 -5
  68. package/templates/scheduled/js/.editorconfig +0 -1
  69. package/templates/scheduled/js/wrangler.toml +94 -0
  70. package/templates/scheduled/ts/.editorconfig +0 -1
  71. package/templates/scheduled/ts/wrangler.toml +94 -0
  72. package/templates/solid/c3.ts +58 -13
  73. package/templates/svelte/c3.ts +83 -30
  74. package/templates/svelte/js/wrangler.toml +52 -0
  75. package/templates/svelte/ts/wrangler.toml +52 -0
  76. package/templates/vue/c3.ts +7 -6
  77. package/templates/next/templates.ts +0 -281
  78. package/templates/solid/js/vite.config.js +0 -12
  79. package/templates/solid/ts/vite.config.ts +0 -12
  80. package/templates/svelte/templates.ts +0 -13
@@ -1,29 +1,22 @@
1
- import { existsSync, mkdirSync } from "fs";
1
+ import { join } from "path";
2
2
  import { crash, updateStatus, warn } from "@cloudflare/cli";
3
3
  import { processArgument } from "@cloudflare/cli/args";
4
4
  import { brandColor, dim } from "@cloudflare/cli/colors";
5
- import { installPackages, runFrameworkGenerator } from "helpers/command";
5
+ import { spinner } from "@cloudflare/cli/interactive";
6
+ import { runFrameworkGenerator } from "frameworks/index";
6
7
  import {
7
- compatDateFlag,
8
+ copyFile,
8
9
  probePaths,
10
+ readFile,
9
11
  readJSON,
10
12
  usesEslint,
11
13
  usesTypescript,
12
14
  writeFile,
13
15
  writeJSON,
14
16
  } from "helpers/files";
15
- import { detectPackageManager } from "helpers/packages";
16
- import {
17
- apiAppDirHelloJs,
18
- apiAppDirHelloTs,
19
- apiPagesDirHelloJs,
20
- apiPagesDirHelloTs,
21
- appDirNotFoundJs,
22
- appDirNotFoundTs,
23
- envDts,
24
- nextConfig,
25
- readme,
26
- } from "./templates";
17
+ import { detectPackageManager } from "helpers/packageManagers";
18
+ import { installPackages } from "helpers/packages";
19
+ import { getTemplatePath } from "../../src/templates";
27
20
  import type { TemplateConfig } from "../../src/templates";
28
21
  import type { C3Args, C3Context } from "types";
29
22
 
@@ -33,27 +26,53 @@ const generate = async (ctx: C3Context) => {
33
26
  const projectName = ctx.project.name;
34
27
 
35
28
  await runFrameworkGenerator(ctx, [projectName]);
36
- };
37
29
 
38
- const getApiTemplate = (
39
- apiPath: string,
40
- isTypescript: boolean
41
- ): [string, string] => {
42
- const isAppDir = /\/app\/api$/.test(apiPath);
30
+ const wranglerToml = readFile(join(getTemplatePath(ctx), "wrangler.toml"));
43
31
 
44
- if (isAppDir) {
45
- // App directory uses route handlers that are defined in a subdirectory (`/api/hello/route.ts`).
46
- const routeHandlerPath = `${apiPath}/hello`;
47
- mkdirSync(routeHandlerPath, { recursive: true });
32
+ // Note: here we add `# KV Example:` to the toml file for the KV example, we don't actually
33
+ // include the comment in the template wrangler.toml file just so to keep it identical
34
+ // and consistent with that of all the other frameworks
35
+ // (instead of making it a special case which needs extra care)
36
+ const newTomlContent = wranglerToml.replace(
37
+ /#\s+\[\[kv_namespaces\]\]\n#\s+binding\s+=\s+"MY_KV_NAMESPACE"\n#\s+id\s+=\s+"[a-zA-Z0-9]+?"/,
38
+ ($1) => `# KV Example:\n${$1}`
39
+ );
48
40
 
49
- return isTypescript
50
- ? [`${routeHandlerPath}/route.ts`, apiAppDirHelloTs]
51
- : [`${routeHandlerPath}/route.js`, apiAppDirHelloJs];
41
+ if (!/# KV Example/.test(newTomlContent)) {
42
+ // This should never happen to users, it is a check mostly so that
43
+ // if the toml file is changed in a way that breaks the "KV Example" addition
44
+ // the C3 Next.js e2e runs will fail with this
45
+ crash("Failed to properly generate the wrangler.toml file");
52
46
  }
53
47
 
54
- return isTypescript
55
- ? [`${apiPath}/hello.ts`, apiPagesDirHelloTs]
56
- : [`${apiPath}/hello.js`, apiPagesDirHelloJs];
48
+ writeFile(join(ctx.project.path, "wrangler.toml"), newTomlContent);
49
+
50
+ updateStatus("Created wrangler.toml file");
51
+ };
52
+
53
+ const updateNextConfig = () => {
54
+ const s = spinner();
55
+
56
+ const configFile = "next.config.mjs";
57
+ s.start(`Updating \`${configFile}\``);
58
+
59
+ const configContent = readFile(configFile);
60
+
61
+ const updatedConfigFile =
62
+ `import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
63
+
64
+ // Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
65
+ // (when running the application with \`next dev\`), for more information see:
66
+ // https://github.com/cloudflare/next-on-pages/blob/5712c57ea7/internal-packages/next-dev/README.md
67
+ if (process.env.NODE_ENV === 'development') {
68
+ await setupDevPlatform();
69
+ }
70
+
71
+ `.replace(/\n\t*/g, "\n") + configContent;
72
+
73
+ writeFile(configFile, updatedConfigFile);
74
+
75
+ s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
57
76
  };
58
77
 
59
78
  const configure = async (ctx: C3Context) => {
@@ -73,36 +92,13 @@ const configure = async (ctx: C3Context) => {
73
92
  crash("Could not find the `/api` or `/app` directory");
74
93
  }
75
94
 
76
- // App directory template may not generate an API route handler, so we update the path to add an `api` directory.
77
- const apiPath = path.replace(/\/app$/, "/app/api");
78
-
79
95
  const usesTs = usesTypescript(ctx);
80
96
 
81
- const appDirPath = probePaths([
82
- `${projectPath}/src/app`,
83
- `${projectPath}/app`,
84
- ]);
85
-
86
- if (appDirPath) {
87
- // Add a custom app not-found edge route as recommended in next-on-pages
88
- // (see: https://github.com/cloudflare/next-on-pages/blob/2b5c8f25/packages/next-on-pages/docs/gotchas.md#not-found)
89
- const notFoundPath = `${appDirPath}/not-found.${usesTs ? "tsx" : "js"}`;
90
- if (!existsSync(notFoundPath)) {
91
- const notFoundContent = usesTs ? appDirNotFoundTs : appDirNotFoundJs;
92
- writeFile(notFoundPath, notFoundContent);
93
- updateStatus("Created a custom edge not-found route");
94
- }
95
- }
96
-
97
- const [handlerPath, handlerFile] = getApiTemplate(
98
- apiPath,
99
- usesTypescript(ctx)
100
- );
101
- writeFile(handlerPath, handlerFile);
102
- updateStatus("Created an example API route handler");
103
-
104
97
  if (usesTs) {
105
- writeFile(`${projectPath}/env.d.ts`, envDts);
98
+ copyFile(
99
+ join(getTemplatePath(ctx), "env.d.ts"),
100
+ join(projectPath, "env.d.ts")
101
+ );
106
102
  updateStatus("Created an env.d.ts file");
107
103
  }
108
104
 
@@ -112,10 +108,12 @@ const configure = async (ctx: C3Context) => {
112
108
  await writeEslintrc(ctx);
113
109
  }
114
110
 
115
- writeFile(`${projectPath}/next.config.mjs`, nextConfig);
116
- updateStatus("Updated the next.config.js file");
111
+ updateNextConfig();
117
112
 
118
- writeFile(`${projectPath}/README.md`, readme);
113
+ copyFile(
114
+ join(getTemplatePath(ctx), "README.md"),
115
+ join(projectPath, "README.md")
116
+ );
119
117
  updateStatus("Updated the README file");
120
118
 
121
119
  await addDevDependencies(installEslintPlugin);
@@ -177,11 +175,40 @@ export default {
177
175
  id: "next",
178
176
  platform: "pages",
179
177
  displayName: "Next",
180
- devScript: "dev",
181
- previewScript: "pages:preview",
182
178
  generate,
183
179
  configure,
184
- transformPackageJson: async () => {
180
+ copyFiles: {
181
+ async selectVariant(ctx) {
182
+ const isApp = probePaths([
183
+ `${ctx.project.path}/src/app`,
184
+ `${ctx.project.path}/app`,
185
+ ]);
186
+
187
+ const isTypescript = usesTypescript(ctx);
188
+
189
+ const dir = isApp ? "app" : "pages";
190
+ return `${dir}/${isTypescript ? "ts" : "js"}`;
191
+ },
192
+ destinationDir(ctx) {
193
+ const srcPath = probePaths([`${ctx.project.path}/src`]);
194
+ return srcPath ? "./src" : "./";
195
+ },
196
+ variants: {
197
+ "app/ts": {
198
+ path: "./app/ts",
199
+ },
200
+ "app/js": {
201
+ path: "./app/js",
202
+ },
203
+ "pages/ts": {
204
+ path: "./pages/ts",
205
+ },
206
+ "pages/js": {
207
+ path: "./pages/js",
208
+ },
209
+ },
210
+ },
211
+ transformPackageJson: async (_, ctx) => {
185
212
  const isNpm = npm === "npm";
186
213
  const isBun = npm === "bun";
187
214
  const isNpmOrBun = isNpm || isBun;
@@ -194,20 +221,16 @@ export default {
194
221
  return {
195
222
  scripts: {
196
223
  "pages:build": `${pmCommand} ${nextOnPagesCommand}`,
197
- "pages:preview": `${pagesBuildRunCommand} && wrangler pages dev .vercel/output/static ${await compatDateFlag()} --compatibility-flag=nodejs_compat`,
198
- "pages:deploy": `${pagesBuildRunCommand} && wrangler pages deploy .vercel/output/static`,
224
+ preview: `${pagesBuildRunCommand} && wrangler pages dev .vercel/output/static`,
225
+ deploy: `${pagesBuildRunCommand} && wrangler pages deploy .vercel/output/static`,
226
+ ...(usesTypescript(ctx) && {
227
+ "build-cf-types": `wrangler types --env-interface CloudflareEnv env.d.ts`,
228
+ }),
199
229
  },
200
230
  };
201
231
  },
202
- testFlags: [
203
- "--typescript",
204
- "--no-install",
205
- "--eslint",
206
- "--tailwind",
207
- "--src-dir",
208
- "--app",
209
- "--import-alias",
210
- "@/*",
211
- ],
232
+ devScript: "dev",
233
+ previewScript: "preview",
234
+ deployScript: "deploy",
212
235
  compatibilityFlags: ["nodejs_compat"],
213
236
  } as TemplateConfig;
@@ -0,0 +1,5 @@
1
+ // Generated by Wrangler
2
+ // by running `wrangler types --env-interface CloudflareEnv env.d.ts`
3
+
4
+ interface CloudflareEnv {
5
+ }
@@ -0,0 +1,23 @@
1
+ import { getRequestContext } from '@cloudflare/next-on-pages'
2
+
3
+ export const config = {
4
+ runtime: 'edge',
5
+ }
6
+
7
+ export default async function handler(req) {
8
+ let responseText = 'Hello World'
9
+
10
+ // In the edge runtime you can use Bindings that are available in your application
11
+ // (for more details see:
12
+ // - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
13
+ // - https://developers.cloudflare.com/pages/functions/bindings/
14
+ // )
15
+ //
16
+ // KV Example:
17
+ // const myKv = getRequestContext().env.MY_KV_NAMESPACE
18
+ // await myKv.put('suffix', ' from a KV store!')
19
+ // const suffix = await myKv.get('suffix')
20
+ // responseText += suffix
21
+
22
+ return new Response(responseText)
23
+ }
@@ -0,0 +1,24 @@
1
+ import type { NextRequest } from 'next/server'
2
+ import { getRequestContext } from '@cloudflare/next-on-pages'
3
+
4
+ export const config = {
5
+ runtime: 'edge',
6
+ }
7
+
8
+ export default async function handler(req: NextRequest) {
9
+ let responseText = 'Hello World'
10
+
11
+ // In the edge runtime you can use Bindings that are available in your application
12
+ // (for more details see:
13
+ // - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
14
+ // - https://developers.cloudflare.com/pages/functions/bindings/
15
+ // )
16
+ //
17
+ // KV Example:
18
+ // const myKv = getRequestContext().env.MY_KV_NAMESPACE
19
+ // await myKv.put('suffix', ' from a KV store!')
20
+ // const suffix = await myKv.get('suffix')
21
+ // responseText += suffix
22
+
23
+ return new Response(responseText)
24
+ }
@@ -0,0 +1,54 @@
1
+ name = "<TBD>"
2
+ compatibility_date = "<TBD>"
3
+ compatibility_flags = ["nodejs_compat"]
4
+
5
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
6
+ # Note: Use secrets to store sensitive data.
7
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
8
+ # [vars]
9
+ # MY_VARIABLE = "production_value"
10
+
11
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
12
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
13
+ # [ai]
14
+ # binding = "AI"
15
+
16
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
17
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
18
+ # [[d1_databases]]
19
+ # binding = "MY_DB"
20
+ # database_name = "my-database"
21
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
22
+
23
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
24
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
25
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
26
+ # [[durable_objects.bindings]]
27
+ # name = "MY_DURABLE_OBJECT"
28
+ # class_name = "MyDurableObject"
29
+ # script_name = 'my-durable-object'
30
+
31
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
32
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
33
+ # [[kv_namespaces]]
34
+ # binding = "MY_KV_NAMESPACE"
35
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
36
+
37
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
38
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
39
+ # [[queues.producers]]
40
+ # binding = "MY_QUEUE"
41
+ # queue = "my-queue"
42
+
43
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
44
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
45
+ # [[r2_buckets]]
46
+ # binding = "MY_BUCKET"
47
+ # bucket_name = "my-bucket"
48
+
49
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
50
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
51
+ # [[services]]
52
+ # binding = "MY_SERVICE"
53
+ # service = "my-service"
54
+
@@ -1,15 +1,17 @@
1
- import { readFileSync } from "node:fs";
2
- import { resolve } from "node:path";
3
1
  import { logRaw } from "@cloudflare/cli";
4
2
  import { brandColor, dim } from "@cloudflare/cli/colors";
5
3
  import { spinner } from "@cloudflare/cli/interactive";
6
- import { runFrameworkGenerator } from "helpers/command";
7
- import { compatDateFlag, writeFile } from "helpers/files";
8
- import { detectPackageManager } from "helpers/packages";
4
+ import { runFrameworkGenerator } from "frameworks/index";
5
+ import { transformFile } from "helpers/codemod";
6
+ import { getLatestTypesEntrypoint } from "helpers/compatDate";
7
+ import { readFile, writeFile } from "helpers/files";
8
+ import { detectPackageManager } from "helpers/packageManagers";
9
+ import { installPackages } from "helpers/packages";
10
+ import * as recast from "recast";
9
11
  import type { TemplateConfig } from "../../src/templates";
10
12
  import type { C3Context } from "types";
11
13
 
12
- const { npm } = detectPackageManager();
14
+ const { npm, name: pm } = detectPackageManager();
13
15
 
14
16
  const generate = async (ctx: C3Context) => {
15
17
  const gitFlag = ctx.args.git ? `--gitInit` : `--no-gitInit`;
@@ -27,19 +29,85 @@ const generate = async (ctx: C3Context) => {
27
29
  logRaw(""); // newline
28
30
  };
29
31
 
30
- const configure = async () => {
31
- const configFileName = "nuxt.config.ts";
32
- const configFilePath = resolve(configFileName);
32
+ const configure = async (ctx: C3Context) => {
33
+ const packages = ["nitro-cloudflare-dev"];
34
+
35
+ // When using pnpm, explicitly add h3 package so the H3Event type declaration can be updated.
36
+ // Package managers other than pnpm will hoist the dependency, as will pnpm with `--shamefully-hoist`
37
+ if (pm === "pnpm") {
38
+ packages.push("h3");
39
+ }
40
+
41
+ await installPackages(packages, {
42
+ dev: true,
43
+ startText: "Installing nitro module `nitro-cloudflare-dev`",
44
+ doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
45
+ });
46
+ updateNuxtConfig();
47
+
48
+ updateEnvTypes(ctx);
49
+ };
50
+
51
+ const updateEnvTypes = (ctx: C3Context) => {
52
+ const filepath = "env.d.ts";
53
+
33
54
  const s = spinner();
34
- s.start(`Updating \`${configFileName}\``);
35
- // Add the cloudflare preset into the configuration file.
36
- const originalConfigFile = readFileSync(configFilePath, "utf8");
37
- const updatedConfigFile = originalConfigFile.replace(
38
- "defineNuxtConfig({",
39
- "defineNuxtConfig({\n nitro: {\n preset: 'cloudflare-pages'\n },"
55
+ s.start(`Updating ${filepath}`);
56
+
57
+ let file = readFile(filepath);
58
+
59
+ let typesEntrypoint = `@cloudflare/workers-types/`;
60
+ const latestEntrypoint = getLatestTypesEntrypoint(ctx);
61
+ if (latestEntrypoint) {
62
+ typesEntrypoint += `/${latestEntrypoint}`;
63
+ }
64
+
65
+ // Replace placeholder with actual types entrypoint
66
+ file = file.replace("WORKERS_TYPES_ENTRYPOINT", typesEntrypoint);
67
+ writeFile("env.d.ts", file);
68
+
69
+ s.stop(`${brandColor(`updated`)} ${dim(`\`${filepath}\``)}`);
70
+ };
71
+
72
+ const updateNuxtConfig = () => {
73
+ const s = spinner();
74
+
75
+ const configFile = "nuxt.config.ts";
76
+ s.start(`Updating \`${configFile}\``);
77
+
78
+ const b = recast.types.builders;
79
+
80
+ const presetDef = b.objectProperty(
81
+ b.identifier("nitro"),
82
+ b.objectExpression([
83
+ b.objectProperty(
84
+ b.identifier("preset"),
85
+ b.stringLiteral("cloudflare-pages")
86
+ ),
87
+ ])
88
+ );
89
+
90
+ const moduleDef = b.objectProperty(
91
+ b.identifier("modules"),
92
+ b.arrayExpression([b.stringLiteral("nitro-cloudflare-dev")])
40
93
  );
41
- writeFile(configFilePath, updatedConfigFile);
42
- s.stop(`${brandColor(`updated`)} ${dim(`\`${configFileName}\``)}`);
94
+
95
+ transformFile(configFile, {
96
+ visitCallExpression: function (n) {
97
+ const callee = n.node.callee as recast.types.namedTypes.Identifier;
98
+ if (callee.name === "defineNuxtConfig") {
99
+ const obj = n.node
100
+ .arguments[0] as recast.types.namedTypes.ObjectExpression;
101
+
102
+ obj.properties.push(presetDef);
103
+ obj.properties.push(moduleDef);
104
+ }
105
+
106
+ return this.traverse(n);
107
+ },
108
+ });
109
+
110
+ s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
43
111
  };
44
112
 
45
113
  const config: TemplateConfig = {
@@ -47,13 +115,20 @@ const config: TemplateConfig = {
47
115
  id: "nuxt",
48
116
  platform: "pages",
49
117
  displayName: "Nuxt",
118
+ copyFiles: {
119
+ path: "./templates",
120
+ },
50
121
  generate,
51
122
  configure,
52
123
  transformPackageJson: async () => ({
53
124
  scripts: {
54
- "pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 3000 -- ${npm} run dev`,
55
- "pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
125
+ deploy: `${npm} run build && wrangler pages deploy ./dist`,
126
+ preview: `${npm} run build && wrangler pages dev ./dist`,
127
+ "build-cf-types": `wrangler types`,
56
128
  },
57
129
  }),
130
+ devScript: "dev",
131
+ deployScript: "deploy",
132
+ previewScript: "preview",
58
133
  };
59
134
  export default config;
@@ -0,0 +1,14 @@
1
+ /// <reference types="WORKERS_TYPES_ENTRYPOINT" />
2
+
3
+ declare module "h3" {
4
+ interface H3EventContext {
5
+ cf: CfProperties;
6
+ cloudflare: {
7
+ request: Request;
8
+ env: Env;
9
+ context: ExecutionContext;
10
+ };
11
+ }
12
+ }
13
+
14
+ export {};
@@ -0,0 +1,4 @@
1
+ // Generated by Wrangler
2
+ // After adding bindings to `wrangler.toml`, regenerate this interface via `npm build-cf-types`
3
+ interface Env {
4
+ }
@@ -0,0 +1,52 @@
1
+ name = "<TBD>"
2
+ compatibility_date = "<TBD>"
3
+
4
+ # Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
5
+ # Note: Use secrets to store sensitive data.
6
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
7
+ # [vars]
8
+ # MY_VARIABLE = "production_value"
9
+
10
+ # Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
11
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
12
+ # [ai]
13
+ # binding = "AI"
14
+
15
+ # Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
16
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
17
+ # [[d1_databases]]
18
+ # binding = "MY_DB"
19
+ # database_name = "my-database"
20
+ # database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
21
+
22
+ # Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
23
+ # Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
24
+ # Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
25
+ # [[durable_objects.bindings]]
26
+ # name = "MY_DURABLE_OBJECT"
27
+ # class_name = "MyDurableObject"
28
+ # script_name = 'my-durable-object'
29
+
30
+ # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
31
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
32
+ # [[kv_namespaces]]
33
+ # binding = "MY_KV_NAMESPACE"
34
+ # id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
35
+
36
+ # Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
37
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
38
+ # [[queues.producers]]
39
+ # binding = "MY_QUEUE"
40
+ # queue = "my-queue"
41
+
42
+ # Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
43
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
44
+ # [[r2_buckets]]
45
+ # binding = "MY_BUCKET"
46
+ # bucket_name = "my-bucket"
47
+
48
+ # Bind another Worker service. Use this binding to call another Worker without network overhead.
49
+ # Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
50
+ # [[services]]
51
+ # binding = "MY_SERVICE"
52
+ # service = "my-service"
@@ -4,8 +4,8 @@ import { join } from "path";
4
4
  import { processArgument } from "@cloudflare/cli/args";
5
5
  import { brandColor, dim } from "@cloudflare/cli/colors";
6
6
  import { runCommand } from "helpers/command";
7
- import { detectPackageManager } from "helpers/packages";
8
- import { chooseAccount } from "../../src/common";
7
+ import { detectPackageManager } from "helpers/packageManagers";
8
+ import { chooseAccount } from "../../src/wrangler/accounts";
9
9
  import type { C3Context } from "types";
10
10
 
11
11
  export async function copyExistingWorkerFiles(ctx: C3Context) {
@@ -3,7 +3,6 @@ root = true
3
3
 
4
4
  [*]
5
5
  indent_style = tab
6
- tab_width = 2
7
6
  end_of_line = lf
8
7
  charset = utf-8
9
8
  trim_trailing_whitespace = true
@@ -4,11 +4,13 @@ export default {
4
4
  displayName: "Queue consumer & producer Worker",
5
5
  platform: "workers",
6
6
  copyFiles: {
7
- js: {
8
- path: "./js",
9
- },
10
- ts: {
11
- path: "./ts",
7
+ variants: {
8
+ js: {
9
+ path: "./js",
10
+ },
11
+ ts: {
12
+ path: "./ts",
13
+ },
12
14
  },
13
15
  },
14
16
  bindings: {
@@ -3,7 +3,6 @@ root = true
3
3
 
4
4
  [*]
5
5
  indent_style = tab
6
- tab_width = 2
7
6
  end_of_line = lf
8
7
  charset = utf-8
9
8
  trim_trailing_whitespace = true