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.
- package/dist/cli.js +934 -855
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/templates/angular/pages/c3.ts +1 -0
- package/templates/astro/pages/c3.ts +1 -0
- package/templates/astro/workers/templates/ts/wrangler.jsonc +1 -1
- package/templates/common/c3.ts +5 -1
- package/templates/docusaurus/pages/c3.ts +1 -0
- package/templates/gatsby/pages/c3.ts +1 -0
- package/templates/hello-world/ts/test/env.d.ts +3 -0
- package/templates/hello-world/ts/worker-configuration.d.ts +6 -2
- package/templates/hello-world-durable-object/c3.ts +4 -1
- package/templates/hello-world-durable-object/ts/worker-configuration.d.ts +6 -4
- package/templates/hello-world-durable-object-with-assets/js/src/index.js +11 -10
- package/templates/hello-world-durable-object-with-assets/js/wrangler.jsonc +2 -2
- package/templates/hello-world-durable-object-with-assets/ts/src/index.ts +10 -9
- package/templates/hello-world-durable-object-with-assets/ts/worker-configuration.d.ts +7 -4
- package/templates/hello-world-durable-object-with-assets/ts/wrangler.jsonc +1 -1
- package/templates/hello-world-with-assets/c3.ts +4 -1
- package/templates/hello-world-with-assets/js/public/index.html +2 -2
- package/templates/hello-world-with-assets/py/public/index.html +2 -2
- package/templates/hello-world-with-assets/ts/public/index.html +2 -2
- package/templates/hello-world-with-assets/ts/test/env.d.ts +3 -0
- package/templates/hello-world-with-assets/ts/test/tsconfig.json +1 -1
- package/templates/hello-world-with-assets/ts/worker-configuration.d.ts +6 -3
- package/templates/hono/c3.ts +5 -66
- package/templates/hono/pages/c3.ts +44 -0
- package/templates/hono/pages/templates/src/index.tsx +12 -0
- package/templates/hono/{templates → pages/templates}/wrangler.jsonc +1 -1
- package/{templates-experimental/hono → templates/hono/workers}/c3.ts +2 -4
- package/templates/next/c3.ts +7 -221
- package/templates/next/pages/c3.ts +225 -0
- package/{templates-experimental/next → templates/next/workers}/c3.ts +6 -7
- package/templates/next/workers/templates/open-next.config.ts +6 -0
- package/{templates-experimental/next → templates/next/workers}/templates/wrangler.jsonc +1 -1
- package/templates/nuxt/pages/c3.ts +2 -0
- package/templates/nuxt/workers/c3.ts +1 -0
- package/templates/openapi/c3.ts +5 -1
- package/templates/pre-existing/c3.ts +5 -1
- package/templates/queues/c3.ts +5 -1
- package/templates/qwik/c3.ts +5 -144
- package/templates/qwik/pages/c3.ts +150 -0
- package/{templates-experimental/qwik → templates/qwik/workers}/c3.ts +2 -2
- package/templates/react/pages/c3.ts +1 -0
- package/templates/react/workers/js/src/App.jsx +1 -1
- package/templates/react/workers/js/{api → worker}/index.js +1 -1
- package/templates/react/workers/js/wrangler.jsonc +2 -2
- package/templates/react/workers/ts/src/App.tsx +1 -1
- package/templates/react/workers/ts/tsconfig.worker.json +1 -1
- package/templates/react/workers/ts/{api → worker}/index.ts +2 -3
- package/templates/react/workers/ts/wrangler.jsonc +2 -2
- package/templates/react-router/c3.ts +53 -0
- package/templates/react-router/templates/worker-configuration.d.ts +8 -0
- package/templates/remix/c3.ts +1 -0
- package/templates/remix/pages/c3.ts +1 -0
- package/templates/scheduled/c3.ts +5 -1
- package/templates/scheduled/ts/src/index.ts +7 -0
- package/templates/svelte/c3.ts +5 -154
- package/templates/svelte/pages/c3.ts +160 -0
- package/{templates-experimental/svelte → templates/svelte/workers}/c3.ts +3 -3
- package/templates/svelte/workers/templates/static/.assetsignore +2 -0
- package/templates/vue/pages/c3.ts +1 -0
- package/templates/vue/workers/js/server/index.js +2 -2
- package/templates/vue/workers/js/wrangler.jsonc +0 -1
- package/templates/vue/workers/ts/server/index.ts +2 -3
- package/templates/vue/workers/ts/wrangler.jsonc +0 -1
- package/templates/hono/snippets/appDeclaration.ts +0 -1
- package/templates-experimental/next/templates/open-next.config.ts +0 -6
- package/templates-experimental/svelte/templates/static/.assetsignore +0 -4
- /package/{templates-experimental/hono → templates/hono/pages}/templates/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/hono → templates/hono/workers}/templates/public/index.html +0 -0
- /package/{templates-experimental/hono → templates/hono/workers}/templates/src/index.ts +0 -0
- /package/templates/hono/{templates → workers/templates}/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/hono → templates/hono/workers}/templates/wrangler.jsonc +0 -0
- /package/templates/next/{README.md → pages/README.md} +0 -0
- /package/templates/next/{app → pages/app}/js/app/api/hello/route.js +0 -0
- /package/templates/next/{app → pages/app}/js/app/not-found.js +0 -0
- /package/templates/next/{app → pages/app}/ts/app/api/hello/route.ts +0 -0
- /package/templates/next/{app → pages/app}/ts/app/not-found.tsx +0 -0
- /package/templates/next/{env.d.ts → pages/env.d.ts} +0 -0
- /package/templates/next/pages/{js → pages/js}/pages/api/hello.js +0 -0
- /package/templates/next/pages/{ts → pages/ts}/pages/api/hello.ts +0 -0
- /package/templates/next/{wrangler.jsonc → pages/wrangler.jsonc} +0 -0
- /package/{templates-experimental/next → templates/next/workers}/templates/.dev.vars +0 -0
- /package/{templates-experimental/next → templates/next/workers}/templates/__dot__gitignore +0 -0
- /package/{templates-experimental/next → templates/next/workers}/templates/cloudflare-env.d.ts +0 -0
- /package/{templates-experimental/qwik → templates/qwik/pages}/snippets/getPlatformProxy.ts +0 -0
- /package/{templates-experimental/qwik → templates/qwik/pages}/templates/worker-configuration.d.ts +0 -0
- /package/templates/qwik/{templates → pages/templates}/wrangler.jsonc +0 -0
- /package/templates/qwik/{snippets → workers/snippets}/getPlatformProxy.ts +0 -0
- /package/{templates-experimental/qwik → templates/qwik/workers}/templates/public/.assetsignore +0 -0
- /package/templates/qwik/{templates → workers/templates}/worker-configuration.d.ts +0 -0
- /package/{templates-experimental/qwik → templates/qwik/workers}/templates/wrangler.jsonc +0 -0
- /package/templates/svelte/{templates → pages/templates}/wrangler.jsonc +0 -0
- /package/{templates-experimental/svelte → templates/svelte/workers}/templates/wrangler.jsonc +0 -0
package/templates/next/c3.ts
CHANGED
|
@@ -1,223 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { inputPrompt, spinner } from "@cloudflare/cli/interactive";
|
|
5
|
-
import { runFrameworkGenerator } from "frameworks/index";
|
|
6
|
-
import {
|
|
7
|
-
copyFile,
|
|
8
|
-
probePaths,
|
|
9
|
-
readFile,
|
|
10
|
-
readJSON,
|
|
11
|
-
usesEslint,
|
|
12
|
-
usesTypescript,
|
|
13
|
-
writeFile,
|
|
14
|
-
writeJSON,
|
|
15
|
-
} from "helpers/files";
|
|
16
|
-
import { detectPackageManager } from "helpers/packageManagers";
|
|
17
|
-
import { installPackages } from "helpers/packages";
|
|
18
|
-
import { getTemplatePath } from "../../src/templates";
|
|
19
|
-
import type { TemplateConfig } from "../../src/templates";
|
|
20
|
-
import type { C3Context } from "types";
|
|
1
|
+
import pages from "./pages/c3";
|
|
2
|
+
import workers from "./workers/c3";
|
|
3
|
+
import type { MultiPlatformTemplateConfig } from "../../src/templates";
|
|
21
4
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const generate = async (ctx: C3Context) => {
|
|
25
|
-
const projectName = ctx.project.name;
|
|
26
|
-
|
|
27
|
-
await runFrameworkGenerator(ctx, [projectName]);
|
|
28
|
-
|
|
29
|
-
const wranglerConfig = readFile(join(getTemplatePath(ctx), "wrangler.jsonc"));
|
|
30
|
-
writeFile(join(ctx.project.path, "wrangler.jsonc"), wranglerConfig);
|
|
31
|
-
updateStatus("Created wrangler.jsonc file");
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const updateNextConfig = (usesTs: boolean) => {
|
|
35
|
-
const s = spinner();
|
|
36
|
-
|
|
37
|
-
const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
|
|
38
|
-
s.start(`Updating \`${configFile}\``);
|
|
39
|
-
|
|
40
|
-
const configContent = readFile(configFile);
|
|
41
|
-
|
|
42
|
-
const updatedConfigFile =
|
|
43
|
-
`import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
|
|
44
|
-
|
|
45
|
-
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to
|
|
46
|
-
// use bindings during local development (when running the application with
|
|
47
|
-
// \`next dev\`). This function is only necessary during development and
|
|
48
|
-
// has no impact outside of that. For more information see:
|
|
49
|
-
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
|
|
50
|
-
setupDevPlatform().catch(console.error);
|
|
51
|
-
|
|
52
|
-
`.replace(/\n\t*/g, "\n") + configContent;
|
|
53
|
-
|
|
54
|
-
writeFile(configFile, updatedConfigFile);
|
|
55
|
-
|
|
56
|
-
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
|
|
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
|
-
throw new Error("Could not find the `/api` or `/app` directory");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const usesTs = usesTypescript(ctx);
|
|
77
|
-
|
|
78
|
-
if (usesTs) {
|
|
79
|
-
copyFile(
|
|
80
|
-
join(getTemplatePath(ctx), "env.d.ts"),
|
|
81
|
-
join(projectPath, "env.d.ts"),
|
|
82
|
-
);
|
|
83
|
-
updateStatus("Created an env.d.ts file");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
87
|
-
|
|
88
|
-
if (installEslintPlugin) {
|
|
89
|
-
await writeEslintrc(ctx);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
updateNextConfig(usesTs);
|
|
93
|
-
|
|
94
|
-
copyFile(
|
|
95
|
-
join(getTemplatePath(ctx), "README.md"),
|
|
96
|
-
join(projectPath, "README.md"),
|
|
97
|
-
);
|
|
98
|
-
updateStatus("Updated the README file");
|
|
99
|
-
|
|
100
|
-
await addDevDependencies(installEslintPlugin);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const shouldInstallNextOnPagesEslintPlugin = async (
|
|
104
|
-
ctx: C3Context,
|
|
105
|
-
): Promise<boolean> => {
|
|
106
|
-
const eslintUsage = usesEslint(ctx);
|
|
107
|
-
|
|
108
|
-
if (!eslintUsage.used) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (eslintUsage.configType !== ".eslintrc.json") {
|
|
113
|
-
warn(
|
|
114
|
-
`Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`,
|
|
115
|
-
);
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return await inputPrompt({
|
|
120
|
-
type: "confirm",
|
|
121
|
-
question: "Do you want to use the next-on-pages eslint-plugin?",
|
|
122
|
-
label: "eslint-plugin",
|
|
123
|
-
defaultValue: true,
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export const writeEslintrc = async (ctx: C3Context): Promise<void> => {
|
|
128
|
-
const eslintConfig = readJSON(`${ctx.project.path}/.eslintrc.json`) as {
|
|
129
|
-
plugins: string[];
|
|
130
|
-
extends: string | string[];
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
eslintConfig.plugins ??= [];
|
|
134
|
-
eslintConfig.plugins.push("eslint-plugin-next-on-pages");
|
|
135
|
-
|
|
136
|
-
if (typeof eslintConfig.extends === "string") {
|
|
137
|
-
eslintConfig.extends = [eslintConfig.extends];
|
|
138
|
-
}
|
|
139
|
-
eslintConfig.extends ??= [];
|
|
140
|
-
eslintConfig.extends.push("plugin:eslint-plugin-next-on-pages/recommended");
|
|
141
|
-
|
|
142
|
-
writeJSON(`${ctx.project.path}/.eslintrc.json`, eslintConfig);
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const addDevDependencies = async (installEslintPlugin: boolean) => {
|
|
146
|
-
const packages = [
|
|
147
|
-
"@cloudflare/next-on-pages@1",
|
|
148
|
-
"@cloudflare/workers-types",
|
|
149
|
-
"vercel",
|
|
150
|
-
...(installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []),
|
|
151
|
-
];
|
|
152
|
-
await installPackages(packages, {
|
|
153
|
-
dev: true,
|
|
154
|
-
startText: "Adding the Cloudflare Pages adapter",
|
|
155
|
-
doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`,
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export default {
|
|
160
|
-
configVersion: 1,
|
|
161
|
-
id: "next",
|
|
162
|
-
frameworkCli: "create-next-app",
|
|
163
|
-
platform: "pages",
|
|
5
|
+
const config: MultiPlatformTemplateConfig = {
|
|
164
6
|
displayName: "Next.js",
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
async selectVariant(ctx) {
|
|
169
|
-
const isApp = probePaths([
|
|
170
|
-
`${ctx.project.path}/src/app`,
|
|
171
|
-
`${ctx.project.path}/app`,
|
|
172
|
-
]);
|
|
173
|
-
|
|
174
|
-
const isTypescript = usesTypescript(ctx);
|
|
175
|
-
|
|
176
|
-
const dir = isApp ? "app" : "pages";
|
|
177
|
-
return `${dir}/${isTypescript ? "ts" : "js"}`;
|
|
178
|
-
},
|
|
179
|
-
destinationDir(ctx) {
|
|
180
|
-
const srcPath = probePaths([`${ctx.project.path}/src`]);
|
|
181
|
-
return srcPath ? "./src" : "./";
|
|
182
|
-
},
|
|
183
|
-
variants: {
|
|
184
|
-
"app/ts": {
|
|
185
|
-
path: "./app/ts",
|
|
186
|
-
},
|
|
187
|
-
"app/js": {
|
|
188
|
-
path: "./app/js",
|
|
189
|
-
},
|
|
190
|
-
"pages/ts": {
|
|
191
|
-
path: "./pages/ts",
|
|
192
|
-
},
|
|
193
|
-
"pages/js": {
|
|
194
|
-
path: "./pages/js",
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
transformPackageJson: async (_, ctx) => {
|
|
199
|
-
const isNpm = npm === "npm";
|
|
200
|
-
const isBun = npm === "bun";
|
|
201
|
-
const isNpmOrBun = isNpm || isBun;
|
|
202
|
-
const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : "";
|
|
203
|
-
const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`;
|
|
204
|
-
const pmCommand = isNpmOrBun ? npx : npm;
|
|
205
|
-
const pagesBuildRunCommand = `${
|
|
206
|
-
isNpm ? "npm run" : isBun ? "bun" : pmCommand
|
|
207
|
-
} pages:build`;
|
|
208
|
-
return {
|
|
209
|
-
scripts: {
|
|
210
|
-
"pages:build": `${pmCommand} ${nextOnPagesCommand}`,
|
|
211
|
-
preview: `${pagesBuildRunCommand} && wrangler pages dev`,
|
|
212
|
-
deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
|
|
213
|
-
...(usesTypescript(ctx) && {
|
|
214
|
-
"cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`,
|
|
215
|
-
}),
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
},
|
|
219
|
-
devScript: "dev",
|
|
220
|
-
previewScript: "preview",
|
|
221
|
-
deployScript: "deploy",
|
|
222
|
-
compatibilityFlags: ["nodejs_compat"],
|
|
223
|
-
} as TemplateConfig;
|
|
7
|
+
platformVariants: { pages, workers },
|
|
8
|
+
};
|
|
9
|
+
export default config;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { updateStatus, warn } from "@cloudflare/cli";
|
|
3
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
4
|
+
import { inputPrompt, spinner } from "@cloudflare/cli/interactive";
|
|
5
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
6
|
+
import {
|
|
7
|
+
copyFile,
|
|
8
|
+
probePaths,
|
|
9
|
+
readFile,
|
|
10
|
+
readJSON,
|
|
11
|
+
usesEslint,
|
|
12
|
+
usesTypescript,
|
|
13
|
+
writeFile,
|
|
14
|
+
writeJSON,
|
|
15
|
+
} from "helpers/files";
|
|
16
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
17
|
+
import { installPackages } from "helpers/packages";
|
|
18
|
+
import { getTemplatePath } from "../../../src/templates";
|
|
19
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
20
|
+
import type { C3Context } from "types";
|
|
21
|
+
|
|
22
|
+
const { npm, npx } = detectPackageManager();
|
|
23
|
+
|
|
24
|
+
const generate = async (ctx: C3Context) => {
|
|
25
|
+
const projectName = ctx.project.name;
|
|
26
|
+
|
|
27
|
+
await runFrameworkGenerator(ctx, [projectName]);
|
|
28
|
+
|
|
29
|
+
const wranglerConfig = readFile(join(getTemplatePath(ctx), "wrangler.jsonc"));
|
|
30
|
+
writeFile(join(ctx.project.path, "wrangler.jsonc"), wranglerConfig);
|
|
31
|
+
updateStatus("Created wrangler.jsonc file");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const updateNextConfig = (usesTs: boolean) => {
|
|
35
|
+
const s = spinner();
|
|
36
|
+
|
|
37
|
+
const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
|
|
38
|
+
s.start(`Updating \`${configFile}\``);
|
|
39
|
+
|
|
40
|
+
const configContent = readFile(configFile);
|
|
41
|
+
|
|
42
|
+
const updatedConfigFile =
|
|
43
|
+
`import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
|
|
44
|
+
|
|
45
|
+
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to
|
|
46
|
+
// use bindings during local development (when running the application with
|
|
47
|
+
// \`next dev\`). This function is only necessary during development and
|
|
48
|
+
// has no impact outside of that. For more information see:
|
|
49
|
+
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
|
|
50
|
+
setupDevPlatform().catch(console.error);
|
|
51
|
+
|
|
52
|
+
`.replace(/\n\t*/g, "\n") + configContent;
|
|
53
|
+
|
|
54
|
+
writeFile(configFile, updatedConfigFile);
|
|
55
|
+
|
|
56
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
|
|
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
|
+
throw new Error("Could not find the `/api` or `/app` directory");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const usesTs = usesTypescript(ctx);
|
|
77
|
+
|
|
78
|
+
if (usesTs) {
|
|
79
|
+
copyFile(
|
|
80
|
+
join(getTemplatePath(ctx), "env.d.ts"),
|
|
81
|
+
join(projectPath, "env.d.ts"),
|
|
82
|
+
);
|
|
83
|
+
updateStatus("Created an env.d.ts file");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
87
|
+
|
|
88
|
+
if (installEslintPlugin) {
|
|
89
|
+
await writeEslintrc(ctx);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
updateNextConfig(usesTs);
|
|
93
|
+
|
|
94
|
+
copyFile(
|
|
95
|
+
join(getTemplatePath(ctx), "README.md"),
|
|
96
|
+
join(projectPath, "README.md"),
|
|
97
|
+
);
|
|
98
|
+
updateStatus("Updated the README file");
|
|
99
|
+
|
|
100
|
+
await addDevDependencies(installEslintPlugin);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const shouldInstallNextOnPagesEslintPlugin = async (
|
|
104
|
+
ctx: C3Context,
|
|
105
|
+
): Promise<boolean> => {
|
|
106
|
+
const eslintUsage = usesEslint(ctx);
|
|
107
|
+
|
|
108
|
+
if (!eslintUsage.used) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (eslintUsage.configType !== ".eslintrc.json") {
|
|
113
|
+
warn(
|
|
114
|
+
`Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`,
|
|
115
|
+
);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return await inputPrompt({
|
|
120
|
+
type: "confirm",
|
|
121
|
+
question: "Do you want to use the next-on-pages eslint-plugin?",
|
|
122
|
+
label: "eslint-plugin",
|
|
123
|
+
defaultValue: true,
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const writeEslintrc = async (ctx: C3Context): Promise<void> => {
|
|
128
|
+
const eslintConfig = readJSON(`${ctx.project.path}/.eslintrc.json`) as {
|
|
129
|
+
plugins: string[];
|
|
130
|
+
extends: string | string[];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
eslintConfig.plugins ??= [];
|
|
134
|
+
eslintConfig.plugins.push("eslint-plugin-next-on-pages");
|
|
135
|
+
|
|
136
|
+
if (typeof eslintConfig.extends === "string") {
|
|
137
|
+
eslintConfig.extends = [eslintConfig.extends];
|
|
138
|
+
}
|
|
139
|
+
eslintConfig.extends ??= [];
|
|
140
|
+
eslintConfig.extends.push("plugin:eslint-plugin-next-on-pages/recommended");
|
|
141
|
+
|
|
142
|
+
writeJSON(`${ctx.project.path}/.eslintrc.json`, eslintConfig);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const addDevDependencies = async (installEslintPlugin: boolean) => {
|
|
146
|
+
const packages = [
|
|
147
|
+
"@cloudflare/next-on-pages@1",
|
|
148
|
+
"@cloudflare/workers-types",
|
|
149
|
+
"vercel",
|
|
150
|
+
...(installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []),
|
|
151
|
+
];
|
|
152
|
+
await installPackages(packages, {
|
|
153
|
+
dev: true,
|
|
154
|
+
startText: "Adding the Cloudflare Pages adapter",
|
|
155
|
+
doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`,
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export default {
|
|
160
|
+
configVersion: 1,
|
|
161
|
+
id: "next",
|
|
162
|
+
frameworkCli: "create-next-app",
|
|
163
|
+
platform: "pages",
|
|
164
|
+
hidden: true,
|
|
165
|
+
displayName: "Next.js",
|
|
166
|
+
path: "templates/next/pages",
|
|
167
|
+
generate,
|
|
168
|
+
configure,
|
|
169
|
+
copyFiles: {
|
|
170
|
+
async selectVariant(ctx) {
|
|
171
|
+
const isApp = probePaths([
|
|
172
|
+
`${ctx.project.path}/src/app`,
|
|
173
|
+
`${ctx.project.path}/app`,
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
const isTypescript = usesTypescript(ctx);
|
|
177
|
+
|
|
178
|
+
const dir = isApp ? "app" : "pages";
|
|
179
|
+
return `${dir}/${isTypescript ? "ts" : "js"}`;
|
|
180
|
+
},
|
|
181
|
+
destinationDir(ctx) {
|
|
182
|
+
const srcPath = probePaths([`${ctx.project.path}/src`]);
|
|
183
|
+
return srcPath ? "./src" : "./";
|
|
184
|
+
},
|
|
185
|
+
variants: {
|
|
186
|
+
"app/ts": {
|
|
187
|
+
path: "./app/ts",
|
|
188
|
+
},
|
|
189
|
+
"app/js": {
|
|
190
|
+
path: "./app/js",
|
|
191
|
+
},
|
|
192
|
+
"pages/ts": {
|
|
193
|
+
path: "./pages/ts",
|
|
194
|
+
},
|
|
195
|
+
"pages/js": {
|
|
196
|
+
path: "./pages/js",
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
transformPackageJson: async (_, ctx) => {
|
|
201
|
+
const isNpm = npm === "npm";
|
|
202
|
+
const isBun = npm === "bun";
|
|
203
|
+
const isNpmOrBun = isNpm || isBun;
|
|
204
|
+
const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : "";
|
|
205
|
+
const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`;
|
|
206
|
+
const pmCommand = isNpmOrBun ? npx : npm;
|
|
207
|
+
const pagesBuildRunCommand = `${
|
|
208
|
+
isNpm ? "npm run" : isBun ? "bun" : pmCommand
|
|
209
|
+
} pages:build`;
|
|
210
|
+
return {
|
|
211
|
+
scripts: {
|
|
212
|
+
"pages:build": `${pmCommand} ${nextOnPagesCommand}`,
|
|
213
|
+
preview: `${pagesBuildRunCommand} && wrangler pages dev`,
|
|
214
|
+
deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
|
|
215
|
+
...(usesTypescript(ctx) && {
|
|
216
|
+
"cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`,
|
|
217
|
+
}),
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
devScript: "dev",
|
|
222
|
+
previewScript: "preview",
|
|
223
|
+
deployScript: "deploy",
|
|
224
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
225
|
+
} as TemplateConfig;
|
|
@@ -3,7 +3,7 @@ import { spinner } from "@cloudflare/cli/interactive";
|
|
|
3
3
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
4
4
|
import { readFile, usesTypescript, writeFile } from "helpers/files";
|
|
5
5
|
import { installPackages } from "helpers/packages";
|
|
6
|
-
import type { TemplateConfig } from "
|
|
6
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
7
7
|
import type { C3Context } from "types";
|
|
8
8
|
|
|
9
9
|
const generate = async (ctx: C3Context) => {
|
|
@@ -12,7 +12,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
12
12
|
|
|
13
13
|
const configure = async (ctx: C3Context) => {
|
|
14
14
|
const packages = [
|
|
15
|
-
"@opennextjs/cloudflare
|
|
15
|
+
"@opennextjs/cloudflare@~1.0.0-beta.0 || ^1.0.0",
|
|
16
16
|
"@cloudflare/workers-types",
|
|
17
17
|
];
|
|
18
18
|
await installPackages(packages, {
|
|
@@ -51,11 +51,10 @@ export default {
|
|
|
51
51
|
configVersion: 1,
|
|
52
52
|
id: "next",
|
|
53
53
|
frameworkCli: "create-next-app",
|
|
54
|
-
|
|
55
|
-
frameworkCliPinnedVersion: "~15.2.2",
|
|
54
|
+
frameworkCliPinnedVersion: "~15.2.4",
|
|
56
55
|
platform: "workers",
|
|
57
56
|
displayName: "Next.js (using Node.js compat + Workers Assets)",
|
|
58
|
-
path: "templates
|
|
57
|
+
path: "templates/next/workers",
|
|
59
58
|
copyFiles: {
|
|
60
59
|
path: "./templates",
|
|
61
60
|
},
|
|
@@ -63,8 +62,8 @@ export default {
|
|
|
63
62
|
configure,
|
|
64
63
|
transformPackageJson: async () => ({
|
|
65
64
|
scripts: {
|
|
66
|
-
deploy: `opennextjs-cloudflare &&
|
|
67
|
-
preview: `opennextjs-cloudflare &&
|
|
65
|
+
deploy: `opennextjs-cloudflare build && opennextjs-cloudflare deploy`,
|
|
66
|
+
preview: `opennextjs-cloudflare build && opennextjs-cloudflare preview`,
|
|
68
67
|
"cf-typegen": `wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts`,
|
|
69
68
|
},
|
|
70
69
|
}),
|
|
@@ -21,6 +21,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
21
21
|
ctx.project.name,
|
|
22
22
|
"--packageManager",
|
|
23
23
|
npm,
|
|
24
|
+
"--no-install",
|
|
24
25
|
gitFlag,
|
|
25
26
|
]);
|
|
26
27
|
|
|
@@ -124,6 +125,7 @@ const config: TemplateConfig = {
|
|
|
124
125
|
id: "nuxt",
|
|
125
126
|
frameworkCli: "nuxi",
|
|
126
127
|
platform: "pages",
|
|
128
|
+
hidden: true,
|
|
127
129
|
displayName: "Nuxt",
|
|
128
130
|
copyFiles: {
|
|
129
131
|
path: "./templates",
|
package/templates/openapi/c3.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
2
|
+
|
|
3
|
+
const config: TemplateConfig = {
|
|
2
4
|
configVersion: 1,
|
|
3
5
|
id: "openapi",
|
|
4
6
|
displayName: "API starter (OpenAPI compliant)",
|
|
@@ -8,3 +10,5 @@ export default {
|
|
|
8
10
|
path: "./ts",
|
|
9
11
|
},
|
|
10
12
|
};
|
|
13
|
+
|
|
14
|
+
export default config;
|
|
@@ -6,6 +6,7 @@ import { processArgument } from "helpers/args";
|
|
|
6
6
|
import { runCommand } from "helpers/command";
|
|
7
7
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
8
8
|
import { chooseAccount, wranglerLogin } from "../../src/wrangler/accounts";
|
|
9
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
9
10
|
import type { C3Context } from "types";
|
|
10
11
|
|
|
11
12
|
export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
@@ -63,10 +64,11 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
const config: TemplateConfig = {
|
|
67
68
|
configVersion: 1,
|
|
68
69
|
id: "pre-existing",
|
|
69
70
|
displayName: "Pre-existing Worker (from Dashboard)",
|
|
71
|
+
description: "Fetch a Worker initialized from the Cloudflare dashboard.",
|
|
70
72
|
platform: "workers",
|
|
71
73
|
hidden: true,
|
|
72
74
|
copyFiles: {
|
|
@@ -79,6 +81,8 @@ export default {
|
|
|
79
81
|
}),
|
|
80
82
|
};
|
|
81
83
|
|
|
84
|
+
export default config;
|
|
85
|
+
|
|
82
86
|
export interface ConfigureParams {
|
|
83
87
|
login: (ctx: C3Context) => Promise<boolean>;
|
|
84
88
|
chooseAccount: (ctx: C3Context) => Promise<void>;
|
package/templates/queues/c3.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
2
|
+
|
|
3
|
+
const config: TemplateConfig = {
|
|
2
4
|
configVersion: 1,
|
|
3
5
|
id: "queues",
|
|
4
6
|
displayName: "Queue consumer & producer Worker",
|
|
@@ -26,3 +28,5 @@ export default {
|
|
|
26
28
|
],
|
|
27
29
|
},
|
|
28
30
|
};
|
|
31
|
+
|
|
32
|
+
export default config;
|