create-cloudflare 2.51.7 → 2.52.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.
- package/dist/cli.js +474 -756
- package/package.json +6 -6
- package/templates/hello-world/py/__dot__gitignore +5 -0
- package/templates/hello-world-durable-object/py/__dot__gitignore +5 -0
- package/templates/hello-world-durable-object-with-assets/py/__dot__gitignore +5 -0
- package/templates/hello-world-with-assets/py/__dot__gitignore +5 -0
- package/templates/hello-world-workflows/js/wrangler.jsonc +1 -1
- package/templates/next/c3.ts +68 -7
- package/templates/react-router/c3.ts +2 -1
- package/templates/waku/c3.ts +35 -0
- package/templates/waku/wrangler.jsonc +19 -0
- package/templates/next/pages/README.md +0 -67
- package/templates/next/pages/app/js/app/api/hello/route.js +0 -21
- package/templates/next/pages/app/js/app/not-found.js +0 -58
- package/templates/next/pages/app/ts/app/api/hello/route.ts +0 -21
- package/templates/next/pages/app/ts/app/not-found.tsx +0 -58
- package/templates/next/pages/c3.ts +0 -222
- package/templates/next/pages/pages/js/pages/api/hello.js +0 -23
- package/templates/next/pages/pages/ts/pages/api/hello.ts +0 -24
- package/templates/next/pages/wrangler.jsonc +0 -8
- package/templates/next/workers/c3.ts +0 -71
- package/templates/remix/c3.ts +0 -10
- package/templates/remix/pages/c3.ts +0 -70
- package/templates/remix/pages/templates/worker-configuration.d.ts +0 -4
- package/templates/remix/pages/templates/wrangler.jsonc +0 -5
- package/templates/remix/workers/c3.ts +0 -53
- package/templates/remix/workers/templates/public/.assetsignore +0 -0
- package/templates/remix/workers/templates/worker-configuration.d.ts +0 -4
- package/templates/remix/workers/templates/wrangler.toml +0 -11
- /package/templates/next/{workers/templates → templates}/.dev.vars +0 -0
- /package/templates/next/{workers/templates → templates}/__dot__gitignore +0 -0
- /package/templates/next/{workers/templates → templates}/open-next.config.ts +0 -0
- /package/templates/next/{workers/templates → templates}/public/_headers +0 -0
- /package/templates/next/{workers/templates → templates}/wrangler.jsonc +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloudflare",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.52.0",
|
|
4
4
|
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@babel/parser": "^7.21.3",
|
|
31
31
|
"@babel/types": "^7.21.4",
|
|
32
32
|
"@clack/prompts": "^0.6.3",
|
|
33
|
-
"@cloudflare/workers-types": "^4.
|
|
33
|
+
"@cloudflare/workers-types": "^4.20250927.0",
|
|
34
34
|
"@iarna/toml": "^3.0.0",
|
|
35
35
|
"@types/command-exists": "^1.2.0",
|
|
36
36
|
"@types/cross-spawn": "^6.0.2",
|
|
@@ -73,11 +73,11 @@
|
|
|
73
73
|
"xdg-app-paths": "^8.3.0",
|
|
74
74
|
"yargs": "^17.7.2",
|
|
75
75
|
"@cloudflare/eslint-config-shared": "1.1.0",
|
|
76
|
-
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
77
|
-
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
78
76
|
"@cloudflare/cli": "1.1.2",
|
|
79
|
-
"@cloudflare/vite-plugin": "1.13.
|
|
80
|
-
"
|
|
77
|
+
"@cloudflare/vite-plugin": "1.13.8",
|
|
78
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
79
|
+
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
80
|
+
"wrangler": "4.40.3"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=18.14.1"
|
package/templates/next/c3.ts
CHANGED
|
@@ -1,9 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
2
|
+
import { spinner } from "@cloudflare/cli/interactive";
|
|
3
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
4
|
+
import { readFile, usesTypescript, writeFile } from "helpers/files";
|
|
5
|
+
import { installPackages } from "helpers/packages";
|
|
6
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
7
|
+
import type { C3Context } from "types";
|
|
4
8
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
const generate = async (ctx: C3Context) => {
|
|
10
|
+
await runFrameworkGenerator(ctx, [ctx.project.name]);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const configure = async (ctx: C3Context) => {
|
|
14
|
+
await installPackages(["@opennextjs/cloudflare@^1.3.0"], {
|
|
15
|
+
startText: "Adding the Cloudflare adapter",
|
|
16
|
+
doneText: `${brandColor(`installed`)} @opennextjs/cloudflare)}`,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const usesTs = usesTypescript(ctx);
|
|
20
|
+
|
|
21
|
+
updateNextConfig(usesTs);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const updateNextConfig = (usesTs: boolean) => {
|
|
25
|
+
const s = spinner();
|
|
26
|
+
|
|
27
|
+
const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
|
|
28
|
+
s.start(`Updating \`${configFile}\``);
|
|
29
|
+
|
|
30
|
+
const configContent = readFile(configFile);
|
|
31
|
+
|
|
32
|
+
const updatedConfigFile =
|
|
33
|
+
configContent +
|
|
34
|
+
`
|
|
35
|
+
// added by create cloudflare to enable calling \`getCloudflareContext()\` in \`next dev\`
|
|
36
|
+
import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare';
|
|
37
|
+
initOpenNextCloudflareForDev();
|
|
38
|
+
`.replace(/\n\t*/g, "\n");
|
|
39
|
+
|
|
40
|
+
writeFile(configFile, updatedConfigFile);
|
|
41
|
+
|
|
42
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
|
|
8
43
|
};
|
|
9
|
-
|
|
44
|
+
|
|
45
|
+
const envInterfaceName = "CloudflareEnv";
|
|
46
|
+
const typesPath = "./cloudflare-env.d.ts";
|
|
47
|
+
export default {
|
|
48
|
+
configVersion: 1,
|
|
49
|
+
id: "next",
|
|
50
|
+
frameworkCli: "create-next-app",
|
|
51
|
+
platform: "workers",
|
|
52
|
+
displayName: "Next.js",
|
|
53
|
+
copyFiles: {
|
|
54
|
+
path: "./templates",
|
|
55
|
+
},
|
|
56
|
+
generate,
|
|
57
|
+
configure,
|
|
58
|
+
transformPackageJson: async () => ({
|
|
59
|
+
scripts: {
|
|
60
|
+
deploy: `opennextjs-cloudflare build && opennextjs-cloudflare deploy`,
|
|
61
|
+
preview: `opennextjs-cloudflare build && opennextjs-cloudflare preview`,
|
|
62
|
+
"cf-typegen": `wrangler types --env-interface ${envInterfaceName} ${typesPath}`,
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
devScript: "dev",
|
|
66
|
+
previewScript: "preview",
|
|
67
|
+
deployScript: "deploy",
|
|
68
|
+
typesPath,
|
|
69
|
+
envInterfaceName,
|
|
70
|
+
} as TemplateConfig;
|
|
@@ -10,7 +10,8 @@ const generate = async (ctx: C3Context) => {
|
|
|
10
10
|
await runFrameworkGenerator(ctx, [
|
|
11
11
|
ctx.project.name,
|
|
12
12
|
"--template",
|
|
13
|
-
|
|
13
|
+
// React-router deleted the template here
|
|
14
|
+
"https://github.com/remix-run/react-router-templates/tree/29ac272b9532fe26463a2d2693fc73ff3c1e884b/cloudflare",
|
|
14
15
|
// to prevent asking about git twice, just let c3 do it
|
|
15
16
|
"--no-git-init",
|
|
16
17
|
"--no-install",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
2
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
3
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
4
|
+
import type { C3Context } from "types";
|
|
5
|
+
|
|
6
|
+
const { npm } = detectPackageManager();
|
|
7
|
+
|
|
8
|
+
const generate = async (ctx: C3Context) => {
|
|
9
|
+
await runFrameworkGenerator(ctx, [
|
|
10
|
+
"--project-name",
|
|
11
|
+
ctx.project.name,
|
|
12
|
+
"--template",
|
|
13
|
+
"07_cloudflare",
|
|
14
|
+
]);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const config: TemplateConfig = {
|
|
18
|
+
configVersion: 1,
|
|
19
|
+
id: "waku",
|
|
20
|
+
frameworkCli: "create-waku",
|
|
21
|
+
platform: "workers",
|
|
22
|
+
displayName: "Waku",
|
|
23
|
+
path: "templates/waku",
|
|
24
|
+
generate,
|
|
25
|
+
transformPackageJson: async () => ({
|
|
26
|
+
scripts: {
|
|
27
|
+
deploy: `${npm} run build && wrangler deploy`,
|
|
28
|
+
preview: `NODE_ENV=production ${npm} run build && wrangler dev`,
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
devScript: "dev",
|
|
32
|
+
deployScript: "deploy",
|
|
33
|
+
previewScript: "preview",
|
|
34
|
+
};
|
|
35
|
+
export default config;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<TBD>",
|
|
3
|
+
"main": "./dist/worker/serve-cloudflare.js",
|
|
4
|
+
// https://developers.cloudflare.com/workers/platform/compatibility-dates
|
|
5
|
+
"compatibility_date": "<TBD>",
|
|
6
|
+
// nodejs_als is required for Waku server-side request context
|
|
7
|
+
// It can be removed if only building static pages
|
|
8
|
+
"compatibility_flags": ["nodejs_als"],
|
|
9
|
+
// https://developers.cloudflare.com/workers/static-assets/binding/
|
|
10
|
+
"assets": {
|
|
11
|
+
"binding": "ASSETS",
|
|
12
|
+
"directory": "./dist/assets",
|
|
13
|
+
"html_handling": "drop-trailing-slash",
|
|
14
|
+
"not_found_handling": "404-page"
|
|
15
|
+
},
|
|
16
|
+
"vars": {
|
|
17
|
+
"MAX_ITEMS": 10
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`c3`](https://developers.cloudflare.com/pages/get-started/c3).
|
|
2
|
-
|
|
3
|
-
## Getting Started
|
|
4
|
-
|
|
5
|
-
First, run the development server:
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm run dev
|
|
9
|
-
# or
|
|
10
|
-
yarn dev
|
|
11
|
-
# or
|
|
12
|
-
pnpm dev
|
|
13
|
-
# or
|
|
14
|
-
bun dev
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
18
|
-
|
|
19
|
-
## Cloudflare integration
|
|
20
|
-
|
|
21
|
-
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:
|
|
22
|
-
- `pages:build` to build the application for Pages using the [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages) CLI
|
|
23
|
-
- `preview` to locally preview your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
|
|
24
|
-
- `deploy` to deploy your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
|
|
25
|
-
|
|
26
|
-
> __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/main/internal-packages/next-dev/README.md#recommended-development-workflow))
|
|
27
|
-
|
|
28
|
-
### Bindings
|
|
29
|
-
|
|
30
|
-
Cloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) are what allows you to interact with resources available in the Cloudflare Platform.
|
|
31
|
-
|
|
32
|
-
You can use bindings during development, when previewing locally your application and of course in the deployed application:
|
|
33
|
-
|
|
34
|
-
- 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).
|
|
35
|
-
|
|
36
|
-
- 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/).
|
|
37
|
-
|
|
38
|
-
- 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/).
|
|
39
|
-
|
|
40
|
-
#### KV Example
|
|
41
|
-
|
|
42
|
-
`c3` has added for you an example showing how you can use a KV binding.
|
|
43
|
-
|
|
44
|
-
In order to enable the example:
|
|
45
|
-
- Search for javascript/typescript lines containing the following comment:
|
|
46
|
-
```ts
|
|
47
|
-
// KV Example:
|
|
48
|
-
```
|
|
49
|
-
and uncomment the commented lines below it (also uncomment the relevant imports).
|
|
50
|
-
- In the `wrangler.jsonc` file add the following configuration line:
|
|
51
|
-
```
|
|
52
|
-
"kv_namespaces": [{ "binding": "MY_KV_NAMESPACE", "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }],
|
|
53
|
-
```
|
|
54
|
-
- If you're using TypeScript run the `cf-typegen` script to update the `env.d.ts` file:
|
|
55
|
-
```bash
|
|
56
|
-
npm run cf-typegen
|
|
57
|
-
# or
|
|
58
|
-
yarn cf-typegen
|
|
59
|
-
# or
|
|
60
|
-
pnpm cf-typegen
|
|
61
|
-
# or
|
|
62
|
-
bun cf-typegen
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action.
|
|
66
|
-
|
|
67
|
-
Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` 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.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
2
|
-
|
|
3
|
-
export const runtime = 'edge'
|
|
4
|
-
|
|
5
|
-
export async function GET() {
|
|
6
|
-
const responseText = 'Hello World'
|
|
7
|
-
|
|
8
|
-
// In the edge runtime you can use Bindings that are available in your application
|
|
9
|
-
// (for more details see:
|
|
10
|
-
// - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
|
|
11
|
-
// - https://developers.cloudflare.com/pages/functions/bindings/
|
|
12
|
-
// )
|
|
13
|
-
//
|
|
14
|
-
// KV Example:
|
|
15
|
-
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
16
|
-
// await myKv.put('suffix', ' from a KV store!')
|
|
17
|
-
// const suffix = await myKv.get('suffix')
|
|
18
|
-
// return new Response(responseText + suffix)
|
|
19
|
-
|
|
20
|
-
return new Response(responseText)
|
|
21
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export const runtime = "edge";
|
|
2
|
-
|
|
3
|
-
export default function NotFound() {
|
|
4
|
-
return (
|
|
5
|
-
<>
|
|
6
|
-
<title>404: This page could not be found.</title>
|
|
7
|
-
<div style={styles.error}>
|
|
8
|
-
<div>
|
|
9
|
-
<style
|
|
10
|
-
dangerouslySetInnerHTML={{
|
|
11
|
-
__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)}}`,
|
|
12
|
-
}}
|
|
13
|
-
/>
|
|
14
|
-
<h1 className="next-error-h1" style={styles.h1}>
|
|
15
|
-
404
|
|
16
|
-
</h1>
|
|
17
|
-
<div style={styles.desc}>
|
|
18
|
-
<h2 style={styles.h2}>This page could not be found.</h2>
|
|
19
|
-
</div>
|
|
20
|
-
</div>
|
|
21
|
-
</div>
|
|
22
|
-
</>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const styles = {
|
|
27
|
-
error: {
|
|
28
|
-
fontFamily:
|
|
29
|
-
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
|
|
30
|
-
height: "100vh",
|
|
31
|
-
textAlign: "center",
|
|
32
|
-
display: "flex",
|
|
33
|
-
flexDirection: "column",
|
|
34
|
-
alignItems: "center",
|
|
35
|
-
justifyContent: "center",
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
desc: {
|
|
39
|
-
display: "inline-block",
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
h1: {
|
|
43
|
-
display: "inline-block",
|
|
44
|
-
margin: "0 20px 0 0",
|
|
45
|
-
padding: "0 23px 0 0",
|
|
46
|
-
fontSize: 24,
|
|
47
|
-
fontWeight: 500,
|
|
48
|
-
verticalAlign: "top",
|
|
49
|
-
lineHeight: "49px",
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
h2: {
|
|
53
|
-
fontSize: 14,
|
|
54
|
-
fontWeight: 400,
|
|
55
|
-
lineHeight: "49px",
|
|
56
|
-
margin: 0,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
2
|
-
|
|
3
|
-
export const runtime = 'edge'
|
|
4
|
-
|
|
5
|
-
export async function GET() {
|
|
6
|
-
const responseText = 'Hello World'
|
|
7
|
-
|
|
8
|
-
// In the edge runtime you can use Bindings that are available in your application
|
|
9
|
-
// (for more details see:
|
|
10
|
-
// - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
|
|
11
|
-
// - https://developers.cloudflare.com/pages/functions/bindings/
|
|
12
|
-
// )
|
|
13
|
-
//
|
|
14
|
-
// KV Example:
|
|
15
|
-
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
16
|
-
// await myKv.put('suffix', ' from a KV store!')
|
|
17
|
-
// const suffix = await myKv.get('suffix')
|
|
18
|
-
// return new Response(responseText + suffix)
|
|
19
|
-
|
|
20
|
-
return new Response(responseText)
|
|
21
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export const runtime = "edge";
|
|
2
|
-
|
|
3
|
-
export default function NotFound() {
|
|
4
|
-
return (
|
|
5
|
-
<>
|
|
6
|
-
<title>404: This page could not be found.</title>
|
|
7
|
-
<div style={styles.error}>
|
|
8
|
-
<div>
|
|
9
|
-
<style
|
|
10
|
-
dangerouslySetInnerHTML={{
|
|
11
|
-
__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)}}`,
|
|
12
|
-
}}
|
|
13
|
-
/>
|
|
14
|
-
<h1 className="next-error-h1" style={styles.h1}>
|
|
15
|
-
404
|
|
16
|
-
</h1>
|
|
17
|
-
<div style={styles.desc}>
|
|
18
|
-
<h2 style={styles.h2}>This page could not be found.</h2>
|
|
19
|
-
</div>
|
|
20
|
-
</div>
|
|
21
|
-
</div>
|
|
22
|
-
</>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const styles = {
|
|
27
|
-
error: {
|
|
28
|
-
fontFamily:
|
|
29
|
-
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
|
|
30
|
-
height: "100vh",
|
|
31
|
-
textAlign: "center",
|
|
32
|
-
display: "flex",
|
|
33
|
-
flexDirection: "column",
|
|
34
|
-
alignItems: "center",
|
|
35
|
-
justifyContent: "center",
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
desc: {
|
|
39
|
-
display: "inline-block",
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
h1: {
|
|
43
|
-
display: "inline-block",
|
|
44
|
-
margin: "0 20px 0 0",
|
|
45
|
-
padding: "0 23px 0 0",
|
|
46
|
-
fontSize: 24,
|
|
47
|
-
fontWeight: 500,
|
|
48
|
-
verticalAlign: "top",
|
|
49
|
-
lineHeight: "49px",
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
h2: {
|
|
53
|
-
fontSize: 14,
|
|
54
|
-
fontWeight: 400,
|
|
55
|
-
lineHeight: "49px",
|
|
56
|
-
margin: 0,
|
|
57
|
-
},
|
|
58
|
-
} as const;
|
|
@@ -1,222 +0,0 @@
|
|
|
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
|
-
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
79
|
-
|
|
80
|
-
if (installEslintPlugin) {
|
|
81
|
-
await writeEslintrc(ctx);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
updateNextConfig(usesTs);
|
|
85
|
-
|
|
86
|
-
copyFile(
|
|
87
|
-
join(getTemplatePath(ctx), "README.md"),
|
|
88
|
-
join(projectPath, "README.md"),
|
|
89
|
-
);
|
|
90
|
-
updateStatus("Updated the README file");
|
|
91
|
-
|
|
92
|
-
await addDevDependencies(installEslintPlugin);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const shouldInstallNextOnPagesEslintPlugin = async (
|
|
96
|
-
ctx: C3Context,
|
|
97
|
-
): Promise<boolean> => {
|
|
98
|
-
const eslintUsage = usesEslint(ctx);
|
|
99
|
-
|
|
100
|
-
if (!eslintUsage.used) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (eslintUsage.configType !== ".eslintrc.json") {
|
|
105
|
-
warn(
|
|
106
|
-
`Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`,
|
|
107
|
-
);
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return await inputPrompt({
|
|
112
|
-
type: "confirm",
|
|
113
|
-
question: "Do you want to use the next-on-pages eslint-plugin?",
|
|
114
|
-
label: "eslint-plugin",
|
|
115
|
-
defaultValue: true,
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const writeEslintrc = async (ctx: C3Context): Promise<void> => {
|
|
120
|
-
const eslintConfig = readJSON(`${ctx.project.path}/.eslintrc.json`) as {
|
|
121
|
-
plugins: string[];
|
|
122
|
-
extends: string | string[];
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
eslintConfig.plugins ??= [];
|
|
126
|
-
eslintConfig.plugins.push("eslint-plugin-next-on-pages");
|
|
127
|
-
|
|
128
|
-
if (typeof eslintConfig.extends === "string") {
|
|
129
|
-
eslintConfig.extends = [eslintConfig.extends];
|
|
130
|
-
}
|
|
131
|
-
eslintConfig.extends ??= [];
|
|
132
|
-
eslintConfig.extends.push("plugin:eslint-plugin-next-on-pages/recommended");
|
|
133
|
-
|
|
134
|
-
writeJSON(`${ctx.project.path}/.eslintrc.json`, eslintConfig);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const addDevDependencies = async (installEslintPlugin: boolean) => {
|
|
138
|
-
const packages = [
|
|
139
|
-
"@cloudflare/next-on-pages@1",
|
|
140
|
-
"vercel@47.0.4",
|
|
141
|
-
"next@15.4.6",
|
|
142
|
-
...(installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []),
|
|
143
|
-
];
|
|
144
|
-
await installPackages(packages, {
|
|
145
|
-
dev: true,
|
|
146
|
-
startText: "Adding the Cloudflare Pages adapter",
|
|
147
|
-
doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`,
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const envInterfaceName = "CloudflareEnv";
|
|
152
|
-
const typesPath = "./env.d.ts";
|
|
153
|
-
|
|
154
|
-
export default {
|
|
155
|
-
configVersion: 1,
|
|
156
|
-
id: "next",
|
|
157
|
-
frameworkCli: "create-next-app",
|
|
158
|
-
platform: "pages",
|
|
159
|
-
hidden: true,
|
|
160
|
-
displayName: "Next.js",
|
|
161
|
-
path: "templates/next/pages",
|
|
162
|
-
generate,
|
|
163
|
-
configure,
|
|
164
|
-
copyFiles: {
|
|
165
|
-
async selectVariant(ctx) {
|
|
166
|
-
const isApp = probePaths([
|
|
167
|
-
`${ctx.project.path}/src/app`,
|
|
168
|
-
`${ctx.project.path}/app`,
|
|
169
|
-
]);
|
|
170
|
-
|
|
171
|
-
const isTypescript = usesTypescript(ctx);
|
|
172
|
-
|
|
173
|
-
const dir = isApp ? "app" : "pages";
|
|
174
|
-
return `${dir}/${isTypescript ? "ts" : "js"}`;
|
|
175
|
-
},
|
|
176
|
-
destinationDir(ctx) {
|
|
177
|
-
const srcPath = probePaths([`${ctx.project.path}/src`]);
|
|
178
|
-
return srcPath ? "./src" : "./";
|
|
179
|
-
},
|
|
180
|
-
variants: {
|
|
181
|
-
"app/ts": {
|
|
182
|
-
path: "./app/ts",
|
|
183
|
-
},
|
|
184
|
-
"app/js": {
|
|
185
|
-
path: "./app/js",
|
|
186
|
-
},
|
|
187
|
-
"pages/ts": {
|
|
188
|
-
path: "./pages/ts",
|
|
189
|
-
},
|
|
190
|
-
"pages/js": {
|
|
191
|
-
path: "./pages/js",
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
transformPackageJson: async (_, ctx) => {
|
|
196
|
-
const isNpm = npm === "npm";
|
|
197
|
-
const isBun = npm === "bun";
|
|
198
|
-
const isNpmOrBun = isNpm || isBun;
|
|
199
|
-
const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : "";
|
|
200
|
-
const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`;
|
|
201
|
-
const pmCommand = isNpmOrBun ? npx : npm;
|
|
202
|
-
const pagesBuildRunCommand = `${
|
|
203
|
-
isNpm ? "npm run" : isBun ? "bun" : pmCommand
|
|
204
|
-
} pages:build`;
|
|
205
|
-
return {
|
|
206
|
-
scripts: {
|
|
207
|
-
"pages:build": `${pmCommand} ${nextOnPagesCommand}`,
|
|
208
|
-
preview: `${pagesBuildRunCommand} && wrangler pages dev`,
|
|
209
|
-
deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
|
|
210
|
-
...(usesTypescript(ctx) && {
|
|
211
|
-
"cf-typegen": `wrangler types --env-interface ${envInterfaceName} ${typesPath}`,
|
|
212
|
-
}),
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
},
|
|
216
|
-
devScript: "dev",
|
|
217
|
-
previewScript: "preview",
|
|
218
|
-
deployScript: "deploy",
|
|
219
|
-
compatibilityFlags: ["nodejs_compat"],
|
|
220
|
-
typesPath,
|
|
221
|
-
envInterfaceName,
|
|
222
|
-
} as TemplateConfig;
|