create-cloudflare 2.9.3 → 2.10.0

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 (42) hide show
  1. package/dist/cli.js +73369 -60761
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +8 -5
  4. package/templates/angular/c3.ts +100 -0
  5. package/templates/astro/c3.ts +50 -0
  6. package/templates/common/c3.ts +14 -0
  7. package/templates/docusaurus/c3.ts +27 -0
  8. package/templates/gatsby/c3.ts +46 -0
  9. package/templates/hello-world/c3.ts +14 -0
  10. package/templates/hello-world-durable-object/c3.ts +14 -0
  11. package/templates/hono/c3.ts +25 -0
  12. package/templates/next/c3.ts +212 -0
  13. package/templates/next/templates.ts +281 -0
  14. package/templates/nuxt/c3.ts +59 -0
  15. package/templates/openapi/c3.ts +9 -0
  16. package/templates/pre-existing/c3.ts +84 -0
  17. package/templates/pre-existing/js/.editorconfig +13 -0
  18. package/templates/pre-existing/js/.prettierrc +6 -0
  19. package/templates/{chatgptPlugin/ts → pre-existing/js}/__dot__gitignore +1 -0
  20. package/templates/{chatgptPlugin/ts → pre-existing/js}/package.json +2 -5
  21. package/templates/pre-existing/js/wrangler.toml +3 -0
  22. package/templates/queues/c3.ts +24 -0
  23. package/templates/qwik/c3.ts +36 -0
  24. package/templates/react/c3.ts +29 -0
  25. package/templates/remix/c3.ts +33 -0
  26. package/templates/scheduled/c3.ts +14 -0
  27. package/templates/solid/c3.ts +37 -0
  28. package/templates/solid/js/vite.config.js +12 -0
  29. package/templates/solid/ts/vite.config.ts +12 -0
  30. package/templates/svelte/c3.ts +75 -0
  31. package/templates/svelte/templates.ts +13 -0
  32. package/templates/vue/c3.ts +27 -0
  33. package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
  34. package/templates/chatgptPlugin/ts/README.md +0 -25
  35. package/templates/chatgptPlugin/ts/src/index.ts +0 -33
  36. package/templates/chatgptPlugin/ts/src/search.ts +0 -59
  37. package/templates/chatgptPlugin/ts/wrangler.toml +0 -3
  38. /package/{dist → templates}/angular/templates/server.ts +0 -0
  39. /package/{dist → templates}/angular/templates/src/_routes.json +0 -0
  40. /package/{dist → templates}/angular/templates/tools/alter-polyfills.mjs +0 -0
  41. /package/{dist → templates}/angular/templates/tools/copy-files.mjs +0 -0
  42. /package/{dist → templates}/angular/templates/tools/paths.mjs +0 -0
@@ -0,0 +1,50 @@
1
+ import { logRaw } from "@cloudflare/cli";
2
+ import { brandColor, dim } from "@cloudflare/cli/colors";
3
+ import { runCommand, runFrameworkGenerator } from "helpers/command";
4
+ import { compatDateFlag } from "helpers/files";
5
+ import { detectPackageManager } from "helpers/packages";
6
+ import type { TemplateConfig } from "../../src/templates";
7
+ import type { C3Context } from "types";
8
+
9
+ const { npx } = detectPackageManager();
10
+
11
+ const generate = async (ctx: C3Context) => {
12
+ await runFrameworkGenerator(ctx, [ctx.project.name, "--no-install"]);
13
+
14
+ logRaw(""); // newline
15
+ };
16
+
17
+ const configure = async (ctx: C3Context) => {
18
+ await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
19
+ silent: true,
20
+ startText: "Installing adapter",
21
+ doneText: `${brandColor("installed")} ${dim(
22
+ `via \`${npx} astro add cloudflare\``
23
+ )}`,
24
+ });
25
+ };
26
+
27
+ const config: TemplateConfig = {
28
+ configVersion: 1,
29
+ id: "astro",
30
+ platform: "pages",
31
+ displayName: "Astro",
32
+ generate,
33
+ configure,
34
+ transformPackageJson: async () => ({
35
+ scripts: {
36
+ "pages:dev": `wrangler pages dev ${await compatDateFlag()} -- astro dev`,
37
+ "pages:deploy": `astro build && wrangler pages deploy ./dist`,
38
+ },
39
+ }),
40
+ testFlags: [
41
+ "--skip-houston",
42
+ "--no-install",
43
+ "--no-git",
44
+ "--template",
45
+ "blog",
46
+ "--typescript",
47
+ "strict",
48
+ ],
49
+ };
50
+ export default config;
@@ -0,0 +1,14 @@
1
+ export default {
2
+ configVersion: 1,
3
+ id: "common",
4
+ displayName: "Example router & proxy Worker",
5
+ platform: "workers",
6
+ copyFiles: {
7
+ js: {
8
+ path: "./js",
9
+ },
10
+ ts: {
11
+ path: "./ts",
12
+ },
13
+ },
14
+ };
@@ -0,0 +1,27 @@
1
+ import { runFrameworkGenerator } from "helpers/command";
2
+ import { compatDateFlag } from "helpers/files";
3
+ import { detectPackageManager } from "helpers/packages";
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, [ctx.project.name, "classic"]);
11
+ };
12
+
13
+ const config: TemplateConfig = {
14
+ configVersion: 1,
15
+ id: "docusaurus",
16
+ platform: "pages",
17
+ displayName: "Docusaurus",
18
+ generate,
19
+ transformPackageJson: async () => ({
20
+ scripts: {
21
+ "pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 3000 -- ${npm} run start`,
22
+ "pages:deploy": `${npm} run build && wrangler pages deploy ./build`,
23
+ },
24
+ }),
25
+ testFlags: [`--package-manager`, npm],
26
+ };
27
+ export default config;
@@ -0,0 +1,46 @@
1
+ import { inputPrompt } from "@cloudflare/cli/interactive";
2
+ import { runFrameworkGenerator } from "helpers/command";
3
+ import { compatDateFlag } from "helpers/files";
4
+ import { detectPackageManager } from "helpers/packages";
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 defaultTemplate = "https://github.com/gatsbyjs/gatsby-starter-blog";
12
+
13
+ const useTemplate = await inputPrompt({
14
+ type: "confirm",
15
+ question: "Would you like to use a template?",
16
+ label: "template",
17
+ defaultValue: true,
18
+ });
19
+
20
+ let templateUrl = "";
21
+ if (useTemplate) {
22
+ templateUrl = await inputPrompt({
23
+ type: "text",
24
+ question: `Please specify the url of the template you'd like to use`,
25
+ label: "template",
26
+ defaultValue: defaultTemplate,
27
+ });
28
+ }
29
+
30
+ await runFrameworkGenerator(ctx, ["new", ctx.project.name, templateUrl]);
31
+ };
32
+
33
+ const config: TemplateConfig = {
34
+ configVersion: 1,
35
+ id: "gatsby",
36
+ platform: "pages",
37
+ displayName: "Gatsby",
38
+ generate,
39
+ transformPackageJson: async () => ({
40
+ scripts: {
41
+ "pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 8000 -- ${npm} run develop`,
42
+ "pages:deploy": `${npm} run build && wrangler pages deploy ./public`,
43
+ },
44
+ }),
45
+ };
46
+ export default config;
@@ -0,0 +1,14 @@
1
+ export default {
2
+ configVersion: 1,
3
+ id: "hello-world",
4
+ displayName: '"Hello World" Worker',
5
+ platform: "workers",
6
+ copyFiles: {
7
+ js: {
8
+ path: "./js",
9
+ },
10
+ ts: {
11
+ path: "./ts",
12
+ },
13
+ },
14
+ };
@@ -0,0 +1,14 @@
1
+ export default {
2
+ configVersion: 1,
3
+ id: "hello-world-durable-object",
4
+ displayName: '"Hello World" Durable Object',
5
+ platform: "workers",
6
+ copyFiles: {
7
+ js: {
8
+ path: "./js",
9
+ },
10
+ ts: {
11
+ path: "./ts",
12
+ },
13
+ },
14
+ };
@@ -0,0 +1,25 @@
1
+ import { logRaw } from "@cloudflare/cli";
2
+ import { runFrameworkGenerator } from "helpers/command";
3
+ import type { TemplateConfig } from "../../src/templates";
4
+ import type { C3Context } from "types";
5
+
6
+ const generate = async (ctx: C3Context) => {
7
+ await runFrameworkGenerator(ctx, [
8
+ ctx.project.name,
9
+ "--template",
10
+ "cloudflare-workers",
11
+ ]);
12
+
13
+ logRaw(""); // newline
14
+ };
15
+
16
+ const config: TemplateConfig = {
17
+ configVersion: 1,
18
+ id: "hono",
19
+ displayName: "Hono",
20
+ platform: "workers",
21
+ generate,
22
+ devScript: "dev",
23
+ deployScript: "deploy",
24
+ };
25
+ export default config;
@@ -0,0 +1,212 @@
1
+ import { existsSync, mkdirSync } from "fs";
2
+ import { crash, updateStatus, warn } from "@cloudflare/cli";
3
+ import { processArgument } from "@cloudflare/cli/args";
4
+ import { brandColor, dim } from "@cloudflare/cli/colors";
5
+ import { installPackages, runFrameworkGenerator } from "helpers/command";
6
+ import {
7
+ compatDateFlag,
8
+ probePaths,
9
+ readJSON,
10
+ usesEslint,
11
+ usesTypescript,
12
+ writeFile,
13
+ writeJSON,
14
+ } 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";
27
+ import type { TemplateConfig } from "../../src/templates";
28
+ import type { C3Args, C3Context } from "types";
29
+
30
+ const { npm, npx } = detectPackageManager();
31
+
32
+ const generate = async (ctx: C3Context) => {
33
+ const projectName = ctx.project.name;
34
+
35
+ await runFrameworkGenerator(ctx, [projectName]);
36
+ };
37
+
38
+ const getApiTemplate = (
39
+ apiPath: string,
40
+ isTypescript: boolean
41
+ ): [string, string] => {
42
+ const isAppDir = /\/app\/api$/.test(apiPath);
43
+
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 });
48
+
49
+ return isTypescript
50
+ ? [`${routeHandlerPath}/route.ts`, apiAppDirHelloTs]
51
+ : [`${routeHandlerPath}/route.js`, apiAppDirHelloJs];
52
+ }
53
+
54
+ return isTypescript
55
+ ? [`${apiPath}/hello.ts`, apiPagesDirHelloTs]
56
+ : [`${apiPath}/hello.js`, apiPagesDirHelloJs];
57
+ };
58
+
59
+ const configure = async (ctx: C3Context) => {
60
+ const projectPath = ctx.project.path;
61
+
62
+ // Add a compatible function handler example
63
+ const path = probePaths([
64
+ `${projectPath}/pages/api`,
65
+ `${projectPath}/src/pages/api`,
66
+ `${projectPath}/src/app/api`,
67
+ `${projectPath}/app/api`,
68
+ `${projectPath}/src/app`,
69
+ `${projectPath}/app`,
70
+ ]);
71
+
72
+ if (!path) {
73
+ crash("Could not find the `/api` or `/app` directory");
74
+ }
75
+
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
+ const usesTs = usesTypescript(ctx);
80
+
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
+ if (usesTs) {
105
+ writeFile(`${projectPath}/env.d.ts`, envDts);
106
+ updateStatus("Created an env.d.ts file");
107
+ }
108
+
109
+ const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
110
+
111
+ if (installEslintPlugin) {
112
+ await writeEslintrc(ctx);
113
+ }
114
+
115
+ writeFile(`${projectPath}/next.config.js`, nextConfig);
116
+ updateStatus("Updated the next.config.js file");
117
+
118
+ writeFile(`${projectPath}/README.md`, readme);
119
+ updateStatus("Updated the README file");
120
+
121
+ await addDevDependencies(installEslintPlugin);
122
+ };
123
+
124
+ export const shouldInstallNextOnPagesEslintPlugin = async (
125
+ ctx: C3Context
126
+ ): Promise<boolean> => {
127
+ const eslintUsage = usesEslint(ctx);
128
+
129
+ if (!eslintUsage.used) return false;
130
+
131
+ if (eslintUsage.configType !== ".eslintrc.json") {
132
+ warn(
133
+ `Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`
134
+ );
135
+ return false;
136
+ }
137
+
138
+ return await processArgument(ctx.args, "eslint-plugin" as keyof C3Args, {
139
+ type: "confirm",
140
+ question: "Do you want to use the next-on-pages eslint-plugin?",
141
+ label: "eslint-plugin",
142
+ defaultValue: true,
143
+ });
144
+ };
145
+
146
+ export const writeEslintrc = async (ctx: C3Context): Promise<void> => {
147
+ const eslintConfig = readJSON(`${ctx.project.path}/.eslintrc.json`);
148
+
149
+ eslintConfig.plugins ??= [];
150
+ eslintConfig.plugins.push("eslint-plugin-next-on-pages");
151
+
152
+ if (typeof eslintConfig.extends === "string") {
153
+ eslintConfig.extends = [eslintConfig.extends];
154
+ }
155
+ eslintConfig.extends ??= [];
156
+ eslintConfig.extends.push("plugin:eslint-plugin-next-on-pages/recommended");
157
+
158
+ writeJSON(`${ctx.project.path}/.eslintrc.json`, eslintConfig);
159
+ };
160
+
161
+ const addDevDependencies = async (installEslintPlugin: boolean) => {
162
+ const packages = [
163
+ "@cloudflare/next-on-pages@1",
164
+ "@cloudflare/workers-types",
165
+ "vercel",
166
+ ...(installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []),
167
+ ];
168
+ await installPackages(packages, {
169
+ dev: true,
170
+ startText: "Adding the Cloudflare Pages adapter",
171
+ doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`,
172
+ });
173
+ };
174
+
175
+ export default {
176
+ configVersion: 1,
177
+ id: "next",
178
+ platform: "pages",
179
+ displayName: "Next",
180
+ devScript: "dev",
181
+ generate,
182
+ configure,
183
+ transformPackageJson: async () => {
184
+ const isNpm = npm === "npm";
185
+ const isBun = npm === "bun";
186
+ const isNpmOrBun = isNpm || isBun;
187
+ const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : "";
188
+ const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`;
189
+ const pmCommand = isNpmOrBun ? npx : npm;
190
+ const pagesBuildRunCommand = `${
191
+ isNpm ? "npm run" : isBun ? "bun" : pmCommand
192
+ } pages:build`;
193
+ return {
194
+ scripts: {
195
+ "pages:build": `${pmCommand} ${nextOnPagesCommand}`,
196
+ "pages:preview": `${pagesBuildRunCommand} && wrangler pages dev .vercel/output/static ${await compatDateFlag()} --compatibility-flag=nodejs_compat`,
197
+ "pages:deploy": `${pagesBuildRunCommand} && wrangler pages deploy .vercel/output/static`,
198
+ },
199
+ };
200
+ },
201
+ testFlags: [
202
+ "--typescript",
203
+ "--no-install",
204
+ "--eslint",
205
+ "--tailwind",
206
+ "--src-dir",
207
+ "--app",
208
+ "--import-alias",
209
+ "@/*",
210
+ ],
211
+ compatibilityFlags: ["nodejs_compat"],
212
+ } as TemplateConfig;
@@ -0,0 +1,281 @@
1
+ const handlerCode = ` let responseText = 'Hello World'
2
+
3
+ // In the edge runtime you can use Bindings that are available in your application
4
+ // (for more details see:
5
+ // - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
6
+ // - https://developers.cloudflare.com/pages/functions/bindings/
7
+ // )
8
+ //
9
+ // KV Example:
10
+ // const myKv = process.env.MY_KV
11
+ // await myKv.put('suffix', ' from a KV store!')
12
+ // const suffix = await myKv.get('suffix')
13
+ // responseText += suffix
14
+
15
+ return new Response(responseText)`;
16
+
17
+ export const apiPagesDirHelloTs = `// Next.js Edge API Routes: https://nextjs.org/docs/pages/building-your-application/routing/api-routes#edge-api-routes
18
+
19
+ import type { NextRequest } from 'next/server'
20
+
21
+ export const config = {
22
+ runtime: 'edge',
23
+ }
24
+
25
+ export default async function handler(req: NextRequest) {
26
+ ${handlerCode}
27
+ }
28
+ `;
29
+
30
+ export const apiPagesDirHelloJs = `// Next.js Edge API Routes: https://nextjs.org/docs/pages/building-your-application/routing/api-routes#edge-api-routes
31
+
32
+ export const config = {
33
+ runtime: 'edge',
34
+ }
35
+
36
+ export default async function handler(req) {
37
+ ${handlerCode}
38
+ }
39
+ `;
40
+
41
+ export const apiAppDirHelloTs = `// Next.js Edge API Route Handlers: https://nextjs.org/docs/app/building-your-application/routing/router-handlers#edge-and-nodejs-runtimes
42
+
43
+ import type { NextRequest } from 'next/server'
44
+
45
+ export const runtime = 'edge'
46
+
47
+ export async function GET(request: NextRequest) {
48
+ ${handlerCode}
49
+ }
50
+ `;
51
+
52
+ export const apiAppDirHelloJs = `// Next.js Edge API Route Handlers: https://nextjs.org/docs/app/building-your-application/routing/router-handlers#edge-and-nodejs-runtimes
53
+
54
+ export const runtime = 'edge'
55
+
56
+ export async function GET(request) {
57
+ ${handlerCode}
58
+ }
59
+ `;
60
+
61
+ // Simplified and adjusted version of the Next.js built-in not-found component (https://github.com/vercel/next.js/blob/1c65c5575/packages/next/src/client/components/not-found-error.tsx)
62
+ export const appDirNotFoundJs = `export const runtime = "edge";
63
+
64
+ export default function NotFound() {
65
+ return (
66
+ <>
67
+ <title>404: This page could not be found.</title>
68
+ <div style={styles.error}>
69
+ <div>
70
+ <style
71
+ dangerouslySetInnerHTML={{
72
+ __html: \`body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\`,
73
+ }}
74
+ />
75
+ <h1 className="next-error-h1" style={styles.h1}>
76
+ 404
77
+ </h1>
78
+ <div style={styles.desc}>
79
+ <h2 style={styles.h2}>This page could not be found.</h2>
80
+ </div>
81
+ </div>
82
+ </div>
83
+ </>
84
+ );
85
+ }
86
+
87
+ const styles = {
88
+ error: {
89
+ fontFamily:
90
+ 'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
91
+ height: "100vh",
92
+ textAlign: "center",
93
+ display: "flex",
94
+ flexDirection: "column",
95
+ alignItems: "center",
96
+ justifyContent: "center",
97
+ },
98
+
99
+ desc: {
100
+ display: "inline-block",
101
+ },
102
+
103
+ h1: {
104
+ display: "inline-block",
105
+ margin: "0 20px 0 0",
106
+ padding: "0 23px 0 0",
107
+ fontSize: 24,
108
+ fontWeight: 500,
109
+ verticalAlign: "top",
110
+ lineHeight: "49px",
111
+ },
112
+
113
+ h2: {
114
+ fontSize: 14,
115
+ fontWeight: 400,
116
+ lineHeight: "49px",
117
+ margin: 0,
118
+ },
119
+ };
120
+ `;
121
+
122
+ // Simplified and adjusted version of the Next.js built-in not-found component (https://github.com/vercel/next.js/blob/1c65c5575/packages/next/src/client/components/not-found-error.tsx)
123
+ export const appDirNotFoundTs = `export const runtime = "edge";
124
+
125
+ export default function NotFound() {
126
+ return (
127
+ <>
128
+ <title>404: This page could not be found.</title>
129
+ <div style={styles.error}>
130
+ <div>
131
+ <style
132
+ dangerouslySetInnerHTML={{
133
+ __html: \`body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\`,
134
+ }}
135
+ />
136
+ <h1 className="next-error-h1" style={styles.h1}>
137
+ 404
138
+ </h1>
139
+ <div style={styles.desc}>
140
+ <h2 style={styles.h2}>This page could not be found.</h2>
141
+ </div>
142
+ </div>
143
+ </div>
144
+ </>
145
+ );
146
+ }
147
+
148
+ const styles = {
149
+ error: {
150
+ fontFamily:
151
+ 'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
152
+ height: "100vh",
153
+ textAlign: "center",
154
+ display: "flex",
155
+ flexDirection: "column",
156
+ alignItems: "center",
157
+ justifyContent: "center",
158
+ },
159
+
160
+ desc: {
161
+ display: "inline-block",
162
+ },
163
+
164
+ h1: {
165
+ display: "inline-block",
166
+ margin: "0 20px 0 0",
167
+ padding: "0 23px 0 0",
168
+ fontSize: 24,
169
+ fontWeight: 500,
170
+ verticalAlign: "top",
171
+ lineHeight: "49px",
172
+ },
173
+
174
+ h2: {
175
+ fontSize: 14,
176
+ fontWeight: 400,
177
+ lineHeight: "49px",
178
+ margin: 0,
179
+ },
180
+ } as const;
181
+ `;
182
+
183
+ export const nextConfig = `/** @type {import('next').NextConfig} */
184
+ const nextConfig = {}
185
+
186
+ module.exports = nextConfig
187
+
188
+ // Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
189
+ // (when running the application with \`next dev\`), for more information see:
190
+ // https://github.com/dario-piotrowicz/next-on-pages/blob/8e93067/internal-packages/next-dev/README.md
191
+ if (process.env.NODE_ENV === 'development') {
192
+ import('@cloudflare/next-on-pages/next-dev').then(({ setupDevBindings }) => {
193
+ setupDevBindings({
194
+ bindings: {
195
+ // Add here the Cloudflare Bindings you want to have available during local development,
196
+ // for more details on Bindings see: https://developers.cloudflare.com/pages/functions/bindings/)
197
+ //
198
+ // KV Example:
199
+ // MY_KV: {
200
+ // type: 'kv',
201
+ // id: 'xxx',
202
+ // }
203
+ }
204
+ })
205
+ })
206
+ }
207
+ `;
208
+
209
+ export const envDts = `declare global {
210
+ namespace NodeJS {
211
+ interface ProcessEnv {
212
+ // Add here the Cloudflare Bindings you want to have available in your application
213
+ // (for more details on Bindings see: https://developers.cloudflare.com/pages/functions/bindings/)
214
+ //
215
+ // KV Example:
216
+ // MY_KV: KVNamespace
217
+ }
218
+ }
219
+ }
220
+
221
+ export {}
222
+ `;
223
+
224
+ export const readme = `This is a [Next.js](https://nextjs.org/) project bootstrapped with [\`c3\`](https://developers.cloudflare.com/pages/get-started/c3).
225
+
226
+ ## Getting Started
227
+
228
+ First, run the development server:
229
+
230
+ \`\`\`bash
231
+ npm run dev
232
+ # or
233
+ yarn dev
234
+ # or
235
+ pnpm dev
236
+ # or
237
+ bun dev
238
+ \`\`\`
239
+
240
+ Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
241
+
242
+ ## Cloudflare integration
243
+
244
+ Besides the \`dev\` script mentioned above \`c3\` has added a few extra scripts that allow you to integrate the application with the [Cloudflare Pages](https://pages.cloudflare.com/) environment, these are:
245
+ - \`pages:build\` to build the application for Pages using the [\`@cloudflare/next-on-pages\`](https://github.com/cloudflare/next-on-pages) CLI
246
+ - \`pages:preview\` to locally preview your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
247
+ - \`pages:deploy\` to deploy your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
248
+
249
+ > __Note:__ while the \`dev\` script is optimal for local development you should preview your Pages application as well (periodically or before deployments) in order to make sure that it can properly work in the Pages environment (for more details see the [\`@cloudflare/next-on-pages\` recommended workflow](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md#recommended-workflow))
250
+
251
+ ### Bindings
252
+
253
+ Cloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) are what allows you to interact with resources available in the Cloudflare Platform.
254
+
255
+ You can use bindings during development, when previewing locally your application and of course in the deployed application:
256
+
257
+ - To use bindings in dev mode you need to define them in the \`next.config.js\` file under \`setupDevBindings\`, this mode uses the \`next-dev\` \`@cloudflare/next-on-pages\` submodule. For more details see its [documentation](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md).
258
+
259
+ - To use bindings in the preview mode you need to add them to the \`pages:preview\` script accordingly to the \`wrangler pages dev\` command. For more details see its [documentation](https://developers.cloudflare.com/workers/wrangler/commands/#dev-1) or the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
260
+
261
+ - To use bindings in the deployed application you will need to configure them in the Cloudflare [dashboard](https://dash.cloudflare.com/). For more details see the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
262
+
263
+ #### KV Example
264
+
265
+ \`c3\` has added for you an example showing how you can use a KV binding, in order to enable the example, search for lines containing the following comment:
266
+ \`\`\`ts
267
+ // KV Example:
268
+ \`\`\`
269
+
270
+ and uncomment the commented lines below it.
271
+
272
+ After doing this you can run the \`dev\` script and visit the \`/api/hello\` route to see the example in action.
273
+
274
+ To then enable such example also in preview mode add a \`kv\` in the \`pages:preview\` script like so:
275
+ \`\`\`diff
276
+ - "pages:preview": "npm run pages:build && wrangler pages dev .vercel/output/static --compatibility-date=2023-12-18 --compatibility-flag=nodejs_compat",
277
+ + "pages:preview": "npm run pages:build && wrangler pages dev .vercel/output/static --compatibility-date=2023-12-18 --compatibility-flag=nodejs_compat --kv MY_KV",
278
+ \`\`\`
279
+
280
+ Finally, if you also want to see the example work in the deployed application make sure to add a \`MY_KV\` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application.
281
+ `;