create-cloudflare 0.0.0-e93d240f → 0.0.0-e9f8a2fa
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.
- package/README.md +1 -52
- package/dist/cli.js +71696 -52359
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +25 -17
- package/templates/analog/c3.ts +134 -0
- package/templates/analog/snippets/devBindingsModule.ts +7 -0
- package/templates/analog/templates/env.d.ts +13 -0
- package/templates/analog/templates/src/dev-bindings.ts +18 -0
- package/templates/analog/templates/worker-configuration.d.ts +4 -0
- package/templates/analog/templates/wrangler.toml +85 -0
- package/templates/angular/c3.ts +100 -0
- package/{dist/angular/templates/src/main.server.ts → templates/angular/templates/server.ts} +14 -15
- package/templates/angular/templates/tools/alter-polyfills.mjs +27 -0
- package/templates/angular/templates/tools/copy-files.mjs +9 -0
- package/templates/astro/c3.ts +112 -0
- package/templates/astro/snippets/runtimeDeclaration.ts +5 -0
- package/templates/astro/templates/wrangler.toml +85 -0
- package/templates/common/c3.ts +16 -0
- package/templates/common/js/.editorconfig +0 -1
- package/templates/common/js/__dot__gitignore +172 -0
- package/templates/common/js/package.json +1 -0
- package/templates/common/js/wrangler.toml +79 -23
- package/templates/common/ts/.editorconfig +0 -1
- package/templates/common/ts/__dot__gitignore +172 -0
- package/templates/common/ts/package.json +3 -2
- package/templates/common/ts/src/index.ts +3 -0
- package/templates/common/ts/worker-configuration.d.ts +2 -14
- package/templates/common/ts/wrangler.toml +79 -23
- package/templates/docusaurus/c3.ts +26 -0
- package/templates/gatsby/c3.ts +48 -0
- package/templates/hello-world/c3.ts +16 -0
- package/templates/hello-world/js/.editorconfig +0 -1
- package/templates/hello-world/js/__dot__gitignore +172 -0
- package/templates/hello-world/js/package.json +6 -2
- package/templates/hello-world/js/test/index.spec.js +20 -0
- package/templates/hello-world/js/vitest.config.js +11 -0
- package/templates/hello-world/js/wrangler.toml +80 -23
- package/templates/hello-world/ts/.editorconfig +0 -1
- package/templates/hello-world/ts/__dot__gitignore +172 -0
- package/templates/hello-world/ts/package.json +7 -3
- package/templates/hello-world/ts/src/index.ts +3 -17
- package/templates/hello-world/ts/test/index.spec.ts +25 -0
- package/templates/hello-world/ts/test/tsconfig.json +11 -0
- package/templates/hello-world/ts/tsconfig.json +3 -2
- package/templates/hello-world/ts/vitest.config.ts +11 -0
- package/templates/hello-world/ts/worker-configuration.d.ts +4 -0
- package/templates/hello-world/ts/wrangler.toml +80 -23
- package/templates/hello-world-durable-object/c3.ts +16 -0
- package/templates/hello-world-durable-object/js/.editorconfig +12 -0
- package/templates/hello-world-durable-object/js/.prettierrc +6 -0
- package/templates/hello-world-durable-object/js/__dot__gitignore +172 -0
- package/templates/hello-world-durable-object/js/package.json +13 -0
- package/templates/hello-world-durable-object/js/src/index.js +69 -0
- package/templates/hello-world-durable-object/js/wrangler.toml +107 -0
- package/templates/hello-world-durable-object/ts/.editorconfig +12 -0
- package/templates/hello-world-durable-object/ts/.prettierrc +6 -0
- package/templates/hello-world-durable-object/ts/__dot__gitignore +172 -0
- package/templates/hello-world-durable-object/ts/package.json +15 -0
- package/templates/hello-world-durable-object/ts/src/index.ts +86 -0
- package/templates/hello-world-durable-object/ts/tsconfig.json +101 -0
- package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +6 -0
- package/templates/hello-world-durable-object/ts/wrangler.toml +107 -0
- package/templates/hello-world-python/c3.ts +9 -0
- package/templates/hello-world-python/py/__dot__gitignore +68 -0
- package/templates/hello-world-python/py/package.json +13 -0
- package/templates/hello-world-python/py/src/entry.py +4 -0
- package/templates/hello-world-python/py/wrangler.toml +108 -0
- package/templates/hono/c3.ts +78 -0
- package/templates/hono/snippets/appDeclaration.ts +1 -0
- package/templates/hono/snippets/bindingsType.ts +3 -0
- package/templates/hono/templates/worker-configuration.d.ts +4 -0
- package/templates/hono/templates/wrangler.toml +107 -0
- package/templates/next/README.md +68 -0
- package/templates/next/app/js/app/api/hello/route.js +21 -0
- package/templates/next/app/js/app/not-found.js +58 -0
- package/templates/next/app/ts/app/api/hello/route.ts +22 -0
- package/templates/next/app/ts/app/not-found.tsx +58 -0
- package/templates/next/c3.ts +238 -0
- package/templates/next/env.d.ts +5 -0
- package/templates/next/pages/js/pages/api/hello.js +23 -0
- package/templates/next/pages/ts/pages/api/hello.ts +24 -0
- package/templates/next/wrangler.toml +86 -0
- package/templates/nuxt/c3.ts +134 -0
- package/templates/nuxt/templates/env.d.ts +14 -0
- package/templates/nuxt/templates/worker-configuration.d.ts +4 -0
- package/templates/nuxt/templates/wrangler.toml +85 -0
- package/templates/openapi/c3.ts +9 -0
- package/templates/openapi/ts/__dot__gitignore +171 -0
- package/templates/openapi/ts/package.json +3 -2
- package/templates/openapi/ts/src/endpoints/taskList.ts +1 -1
- package/templates/openapi/ts/src/index.ts +2 -2
- package/templates/openapi/ts/worker-configuration.d.ts +4 -0
- package/templates/openapi/ts/wrangler.toml +104 -0
- package/templates/pre-existing/c3.ts +83 -0
- package/templates/pre-existing/js/.editorconfig +12 -0
- package/templates/pre-existing/js/.prettierrc +6 -0
- package/templates/pre-existing/js/__dot__gitignore +172 -0
- package/templates/pre-existing/js/package.json +13 -0
- package/templates/pre-existing/js/wrangler.toml +4 -0
- package/templates/queues/c3.ts +26 -0
- package/templates/queues/js/.editorconfig +0 -1
- package/templates/queues/js/__dot__gitignore +172 -0
- package/templates/queues/js/package.json +1 -0
- package/templates/queues/js/wrangler.toml +95 -2
- package/templates/queues/ts/.editorconfig +0 -1
- package/templates/queues/ts/__dot__gitignore +172 -0
- package/templates/queues/ts/package.json +3 -2
- package/templates/queues/ts/src/index.ts +3 -5
- package/templates/queues/ts/worker-configuration.d.ts +5 -0
- package/templates/queues/ts/wrangler.toml +95 -2
- package/templates/qwik/c3.ts +146 -0
- package/templates/qwik/snippets/getPlatformProxy.ts +6 -0
- package/templates/qwik/templates/worker-configuration.d.ts +4 -0
- package/templates/qwik/templates/wrangler.toml +85 -0
- package/templates/react/c3.ts +31 -0
- package/templates/remix/c3.ts +66 -0
- package/templates/remix/templates/worker-configuration.d.ts +4 -0
- package/templates/remix/templates/wrangler.toml +85 -0
- package/templates/scheduled/c3.ts +16 -0
- package/templates/scheduled/js/.editorconfig +0 -1
- package/templates/scheduled/js/__dot__gitignore +172 -0
- package/templates/scheduled/js/package.json +2 -1
- package/templates/scheduled/js/src/index.js +8 -1
- package/templates/scheduled/js/wrangler.toml +105 -1
- package/templates/scheduled/ts/.editorconfig +0 -1
- package/templates/scheduled/ts/__dot__gitignore +172 -0
- package/templates/scheduled/ts/package.json +3 -2
- package/templates/scheduled/ts/src/index.ts +4 -21
- package/templates/scheduled/ts/worker-configuration.d.ts +4 -0
- package/templates/scheduled/ts/wrangler.toml +105 -1
- package/templates/solid/c3.ts +84 -0
- package/templates/solid/templates/wrangler.toml +84 -0
- package/templates/svelte/c3.ts +130 -0
- package/templates/svelte/js/wrangler.toml +85 -0
- package/templates/svelte/ts/wrangler.toml +85 -0
- package/templates/vue/c3.ts +28 -0
- package/dist/angular/templates/tools/bundle.mjs +0 -77
- package/dist/angular/templates/tools/copy-client-files.mjs +0 -4
- package/dist/angular/templates/tools/copy-worker-files.mjs +0 -10
- package/dist/angular/templates/tsconfig.server.json +0 -5
- package/templates/chatgptPlugin/ts/.assets/example.png +0 -0
- package/templates/chatgptPlugin/ts/README.md +0 -25
- package/templates/chatgptPlugin/ts/package.json +0 -16
- package/templates/chatgptPlugin/ts/src/index.ts +0 -33
- package/templates/chatgptPlugin/ts/src/search.ts +0 -59
- package/templates/chatgptPlugin/ts/wrangler.toml +0 -3
- /package/{dist → templates}/angular/templates/src/_routes.json +0 -0
- /package/{dist → templates}/angular/templates/tools/paths.mjs +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { join } from "path";
|
|
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 { spinner } from "@cloudflare/cli/interactive";
|
|
6
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
7
|
+
import {
|
|
8
|
+
copyFile,
|
|
9
|
+
probePaths,
|
|
10
|
+
readFile,
|
|
11
|
+
readJSON,
|
|
12
|
+
usesEslint,
|
|
13
|
+
usesTypescript,
|
|
14
|
+
writeFile,
|
|
15
|
+
writeJSON,
|
|
16
|
+
} from "helpers/files";
|
|
17
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
18
|
+
import { installPackages } from "helpers/packages";
|
|
19
|
+
import { getTemplatePath } from "../../src/templates";
|
|
20
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
21
|
+
import type { C3Args, C3Context } from "types";
|
|
22
|
+
|
|
23
|
+
const { npm, npx } = detectPackageManager();
|
|
24
|
+
|
|
25
|
+
const generate = async (ctx: C3Context) => {
|
|
26
|
+
const projectName = ctx.project.name;
|
|
27
|
+
|
|
28
|
+
await runFrameworkGenerator(ctx, [projectName]);
|
|
29
|
+
|
|
30
|
+
const wranglerToml = readFile(join(getTemplatePath(ctx), "wrangler.toml"));
|
|
31
|
+
|
|
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
|
+
);
|
|
40
|
+
|
|
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");
|
|
46
|
+
}
|
|
47
|
+
|
|
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}\``)}`);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const configure = async (ctx: C3Context) => {
|
|
79
|
+
const projectPath = ctx.project.path;
|
|
80
|
+
|
|
81
|
+
// Add a compatible function handler example
|
|
82
|
+
const path = probePaths([
|
|
83
|
+
`${projectPath}/pages/api`,
|
|
84
|
+
`${projectPath}/src/pages/api`,
|
|
85
|
+
`${projectPath}/src/app/api`,
|
|
86
|
+
`${projectPath}/app/api`,
|
|
87
|
+
`${projectPath}/src/app`,
|
|
88
|
+
`${projectPath}/app`,
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
if (!path) {
|
|
92
|
+
crash("Could not find the `/api` or `/app` directory");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const usesTs = usesTypescript(ctx);
|
|
96
|
+
|
|
97
|
+
if (usesTs) {
|
|
98
|
+
copyFile(
|
|
99
|
+
join(getTemplatePath(ctx), "env.d.ts"),
|
|
100
|
+
join(projectPath, "env.d.ts"),
|
|
101
|
+
);
|
|
102
|
+
updateStatus("Created an env.d.ts file");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
106
|
+
|
|
107
|
+
if (installEslintPlugin) {
|
|
108
|
+
await writeEslintrc(ctx);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
updateNextConfig();
|
|
112
|
+
|
|
113
|
+
copyFile(
|
|
114
|
+
join(getTemplatePath(ctx), "README.md"),
|
|
115
|
+
join(projectPath, "README.md"),
|
|
116
|
+
);
|
|
117
|
+
updateStatus("Updated the README file");
|
|
118
|
+
|
|
119
|
+
await addDevDependencies(installEslintPlugin);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const shouldInstallNextOnPagesEslintPlugin = async (
|
|
123
|
+
ctx: C3Context,
|
|
124
|
+
): Promise<boolean> => {
|
|
125
|
+
const eslintUsage = usesEslint(ctx);
|
|
126
|
+
|
|
127
|
+
if (!eslintUsage.used) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
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
|
+
generate,
|
|
181
|
+
configure,
|
|
182
|
+
copyFiles: {
|
|
183
|
+
async selectVariant(ctx) {
|
|
184
|
+
const isApp = probePaths([
|
|
185
|
+
`${ctx.project.path}/src/app`,
|
|
186
|
+
`${ctx.project.path}/app`,
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
const isTypescript = usesTypescript(ctx);
|
|
190
|
+
|
|
191
|
+
const dir = isApp ? "app" : "pages";
|
|
192
|
+
return `${dir}/${isTypescript ? "ts" : "js"}`;
|
|
193
|
+
},
|
|
194
|
+
destinationDir(ctx) {
|
|
195
|
+
const srcPath = probePaths([`${ctx.project.path}/src`]);
|
|
196
|
+
return srcPath ? "./src" : "./";
|
|
197
|
+
},
|
|
198
|
+
variants: {
|
|
199
|
+
"app/ts": {
|
|
200
|
+
path: "./app/ts",
|
|
201
|
+
},
|
|
202
|
+
"app/js": {
|
|
203
|
+
path: "./app/js",
|
|
204
|
+
},
|
|
205
|
+
"pages/ts": {
|
|
206
|
+
path: "./pages/ts",
|
|
207
|
+
},
|
|
208
|
+
"pages/js": {
|
|
209
|
+
path: "./pages/js",
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
transformPackageJson: async (_, ctx) => {
|
|
214
|
+
const isNpm = npm === "npm";
|
|
215
|
+
const isBun = npm === "bun";
|
|
216
|
+
const isNpmOrBun = isNpm || isBun;
|
|
217
|
+
const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : "";
|
|
218
|
+
const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`;
|
|
219
|
+
const pmCommand = isNpmOrBun ? npx : npm;
|
|
220
|
+
const pagesBuildRunCommand = `${
|
|
221
|
+
isNpm ? "npm run" : isBun ? "bun" : pmCommand
|
|
222
|
+
} pages:build`;
|
|
223
|
+
return {
|
|
224
|
+
scripts: {
|
|
225
|
+
"pages:build": `${pmCommand} ${nextOnPagesCommand}`,
|
|
226
|
+
preview: `${pagesBuildRunCommand} && wrangler pages dev`,
|
|
227
|
+
deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
|
|
228
|
+
...(usesTypescript(ctx) && {
|
|
229
|
+
"cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`,
|
|
230
|
+
}),
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
devScript: "dev",
|
|
235
|
+
previewScript: "preview",
|
|
236
|
+
deployScript: "deploy",
|
|
237
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
238
|
+
} as TemplateConfig;
|
|
@@ -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,86 @@
|
|
|
1
|
+
#:schema node_modules/wrangler/config-schema.json
|
|
2
|
+
name = "<TBD>"
|
|
3
|
+
compatibility_date = "<TBD>"
|
|
4
|
+
compatibility_flags = ["nodejs_compat"]
|
|
5
|
+
pages_build_output_dir = ".vercel/output/static"
|
|
6
|
+
|
|
7
|
+
# Automatically place your workloads in an optimal location to minimize latency.
|
|
8
|
+
# If you are running back-end logic in a Pages Function, running it closer to your back-end infrastructure
|
|
9
|
+
# rather than the end user may result in better performance.
|
|
10
|
+
# Docs: https://developers.cloudflare.com/pages/functions/smart-placement/#smart-placement
|
|
11
|
+
# [placement]
|
|
12
|
+
# mode = "smart"
|
|
13
|
+
|
|
14
|
+
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
15
|
+
# Docs:
|
|
16
|
+
# - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
|
|
17
|
+
# Note: Use secrets to store sensitive data.
|
|
18
|
+
# - https://developers.cloudflare.com/pages/functions/bindings/#secrets
|
|
19
|
+
# [vars]
|
|
20
|
+
# MY_VARIABLE = "production_value"
|
|
21
|
+
|
|
22
|
+
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
|
23
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
|
|
24
|
+
# [ai]
|
|
25
|
+
# binding = "AI"
|
|
26
|
+
|
|
27
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
28
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
|
|
29
|
+
# [[d1_databases]]
|
|
30
|
+
# binding = "MY_DB"
|
|
31
|
+
# database_name = "my-database"
|
|
32
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
33
|
+
|
|
34
|
+
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
35
|
+
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
36
|
+
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
|
|
37
|
+
# [[durable_objects.bindings]]
|
|
38
|
+
# name = "MY_DURABLE_OBJECT"
|
|
39
|
+
# class_name = "MyDurableObject"
|
|
40
|
+
# script_name = 'my-durable-object'
|
|
41
|
+
|
|
42
|
+
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
43
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
|
|
44
|
+
# [[kv_namespaces]]
|
|
45
|
+
# binding = "MY_KV_NAMESPACE"
|
|
46
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
47
|
+
|
|
48
|
+
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
49
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
|
|
50
|
+
# [[queues.producers]]
|
|
51
|
+
# binding = "MY_QUEUE"
|
|
52
|
+
# queue = "my-queue"
|
|
53
|
+
|
|
54
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
55
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
|
|
56
|
+
# [[r2_buckets]]
|
|
57
|
+
# binding = "MY_BUCKET"
|
|
58
|
+
# bucket_name = "my-bucket"
|
|
59
|
+
|
|
60
|
+
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
61
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
|
|
62
|
+
# [[services]]
|
|
63
|
+
# binding = "MY_SERVICE"
|
|
64
|
+
# service = "my-service"
|
|
65
|
+
|
|
66
|
+
# To use different bindings for preview and production environments, follow the examples below.
|
|
67
|
+
# When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
|
|
68
|
+
# Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
|
|
69
|
+
|
|
70
|
+
######## PREVIEW environment config ########
|
|
71
|
+
|
|
72
|
+
# [env.preview.vars]
|
|
73
|
+
# API_KEY = "xyz789"
|
|
74
|
+
|
|
75
|
+
# [[env.preview.kv_namespaces]]
|
|
76
|
+
# binding = "MY_KV_NAMESPACE"
|
|
77
|
+
# id = "<PREVIEW_NAMESPACE_ID>"
|
|
78
|
+
|
|
79
|
+
######## PRODUCTION environment config ########
|
|
80
|
+
|
|
81
|
+
# [env.production.vars]
|
|
82
|
+
# API_KEY = "abc123"
|
|
83
|
+
|
|
84
|
+
# [[env.production.kv_namespaces]]
|
|
85
|
+
# binding = "MY_KV_NAMESPACE"
|
|
86
|
+
# id = "<PRODUCTION_NAMESPACE_ID>"
|
|
@@ -0,0 +1,134 @@
|
|
|
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 { 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";
|
|
11
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
12
|
+
import type { C3Context } from "types";
|
|
13
|
+
|
|
14
|
+
const { npm, name: pm } = detectPackageManager();
|
|
15
|
+
|
|
16
|
+
const generate = async (ctx: C3Context) => {
|
|
17
|
+
const gitFlag = ctx.args.git ? `--gitInit` : `--no-gitInit`;
|
|
18
|
+
|
|
19
|
+
await runFrameworkGenerator(ctx, [
|
|
20
|
+
"init",
|
|
21
|
+
ctx.project.name,
|
|
22
|
+
"--packageManager",
|
|
23
|
+
npm,
|
|
24
|
+
gitFlag,
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
writeFile("./.node-version", "17");
|
|
28
|
+
|
|
29
|
+
logRaw(""); // newline
|
|
30
|
+
};
|
|
31
|
+
|
|
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
|
+
|
|
54
|
+
const s = spinner();
|
|
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")]),
|
|
93
|
+
);
|
|
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}\``)}`);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const config: TemplateConfig = {
|
|
114
|
+
configVersion: 1,
|
|
115
|
+
id: "nuxt",
|
|
116
|
+
platform: "pages",
|
|
117
|
+
displayName: "Nuxt",
|
|
118
|
+
copyFiles: {
|
|
119
|
+
path: "./templates",
|
|
120
|
+
},
|
|
121
|
+
generate,
|
|
122
|
+
configure,
|
|
123
|
+
transformPackageJson: async () => ({
|
|
124
|
+
scripts: {
|
|
125
|
+
deploy: `${npm} run build && wrangler pages deploy`,
|
|
126
|
+
preview: `${npm} run build && wrangler pages dev`,
|
|
127
|
+
"cf-typegen": `wrangler types`,
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
devScript: "dev",
|
|
131
|
+
deployScript: "deploy",
|
|
132
|
+
previewScript: "preview",
|
|
133
|
+
};
|
|
134
|
+
export default config;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#:schema node_modules/wrangler/config-schema.json
|
|
2
|
+
name = "<TBD>"
|
|
3
|
+
compatibility_date = "<TBD>"
|
|
4
|
+
pages_build_output_dir = "./dist"
|
|
5
|
+
|
|
6
|
+
# Automatically place your workloads in an optimal location to minimize latency.
|
|
7
|
+
# If you are running back-end logic in a Pages Function, running it closer to your back-end infrastructure
|
|
8
|
+
# rather than the end user may result in better performance.
|
|
9
|
+
# Docs: https://developers.cloudflare.com/pages/functions/smart-placement/#smart-placement
|
|
10
|
+
# [placement]
|
|
11
|
+
# mode = "smart"
|
|
12
|
+
|
|
13
|
+
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
14
|
+
# Docs:
|
|
15
|
+
# - https://developers.cloudflare.com/pages/functions/bindings/#environment-variables
|
|
16
|
+
# Note: Use secrets to store sensitive data.
|
|
17
|
+
# - https://developers.cloudflare.com/pages/functions/bindings/#secrets
|
|
18
|
+
# [vars]
|
|
19
|
+
# MY_VARIABLE = "production_value"
|
|
20
|
+
|
|
21
|
+
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
|
22
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#workers-ai
|
|
23
|
+
# [ai]
|
|
24
|
+
# binding = "AI"
|
|
25
|
+
|
|
26
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
27
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#d1-databases
|
|
28
|
+
# [[d1_databases]]
|
|
29
|
+
# binding = "MY_DB"
|
|
30
|
+
# database_name = "my-database"
|
|
31
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
32
|
+
|
|
33
|
+
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
34
|
+
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
35
|
+
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
|
|
36
|
+
# [[durable_objects.bindings]]
|
|
37
|
+
# name = "MY_DURABLE_OBJECT"
|
|
38
|
+
# class_name = "MyDurableObject"
|
|
39
|
+
# script_name = 'my-durable-object'
|
|
40
|
+
|
|
41
|
+
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
42
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#kv-namespaces
|
|
43
|
+
# [[kv_namespaces]]
|
|
44
|
+
# binding = "MY_KV_NAMESPACE"
|
|
45
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
46
|
+
|
|
47
|
+
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
48
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#queue-producers
|
|
49
|
+
# [[queues.producers]]
|
|
50
|
+
# binding = "MY_QUEUE"
|
|
51
|
+
# queue = "my-queue"
|
|
52
|
+
|
|
53
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
54
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#r2-buckets
|
|
55
|
+
# [[r2_buckets]]
|
|
56
|
+
# binding = "MY_BUCKET"
|
|
57
|
+
# bucket_name = "my-bucket"
|
|
58
|
+
|
|
59
|
+
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
60
|
+
# Docs: https://developers.cloudflare.com/pages/functions/bindings/#service-bindings
|
|
61
|
+
# [[services]]
|
|
62
|
+
# binding = "MY_SERVICE"
|
|
63
|
+
# service = "my-service"
|
|
64
|
+
|
|
65
|
+
# To use different bindings for preview and production environments, follow the examples below.
|
|
66
|
+
# When using environment-specific overrides for bindings, ALL bindings must be specified on a per-environment basis.
|
|
67
|
+
# Docs: https://developers.cloudflare.com/pages/functions/wrangler-configuration#environment-specific-overrides
|
|
68
|
+
|
|
69
|
+
######## PREVIEW environment config ########
|
|
70
|
+
|
|
71
|
+
# [env.preview.vars]
|
|
72
|
+
# API_KEY = "xyz789"
|
|
73
|
+
|
|
74
|
+
# [[env.preview.kv_namespaces]]
|
|
75
|
+
# binding = "MY_KV_NAMESPACE"
|
|
76
|
+
# id = "<PREVIEW_NAMESPACE_ID>"
|
|
77
|
+
|
|
78
|
+
######## PRODUCTION environment config ########
|
|
79
|
+
|
|
80
|
+
# [env.production.vars]
|
|
81
|
+
# API_KEY = "abc123"
|
|
82
|
+
|
|
83
|
+
# [[env.production.kv_namespaces]]
|
|
84
|
+
# binding = "MY_KV_NAMESPACE"
|
|
85
|
+
# id = "<PRODUCTION_NAMESPACE_ID>"
|