Skip to content

Commit 2d5a308

Browse files
vicbjames-elicx
andauthored
docs(cloudflare): add a section for CLI commands (#184)
Co-authored-by: James Anderson <[email protected]>
1 parent a2aebb1 commit 2d5a308

File tree

6 files changed

+42
-35
lines changed

6 files changed

+42
-35
lines changed

pages/cloudflare/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"index": "Overview",
33
"get-started": "",
4+
"cli": "CLI (opennextjs-cloudflare)",
45
"bindings": "",
56
"caching": "",
67
"howtos": "How-Tos",

pages/cloudflare/bindings.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ To ensure that your types are always up-to-date, make sure to run `wrangler type
5353

5454
## Local access to bindings
5555

56-
As presented in the [getting started](/cloudflare/get-started#12-develop-locally) your application can be both developed (`next dev`) and
57-
previewed (`opennextjs-cloudflare preview`) locally, in both cases bindings will be accessible from your application's code.
56+
As presented in the [getting started](/cloudflare/get-started#12-develop-locally) your application can be both developed (`next dev`) and [previewed locally](/cloudflare/cli#preview-command), in both cases bindings will be accessible from your application's code.
5857

5958
Such bindings are by default local simulation that mimic the behavior of the actual Cloudflare resources.
6059

pages/cloudflare/caching.mdx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -585,25 +585,7 @@ export default defineCloudflareConfig({
585585

586586
In order for the cache to be properly initialised with the build-time revalidation data, you need to run a command as part of your deploy step. This should be run as part of each deployment to ensure that the cache is being populated with each build's data.
587587

588-
To populate remote bindings and create a new [version](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/#versions) of your application at the same time, you can use either the `deploy` command or the `upload` command. Similarly, the `preview` command will populate your local bindings and start a Wrangler dev server.
589-
590-
```sh
591-
# Populate remote and deploy the worker immediately.
592-
opennextjs-cloudflare deploy
593-
594-
# Populate remote and upload a new version of the worker.
595-
opennextjs-cloudflare upload
596-
597-
# Populate local and start dev server.
598-
opennextjs-cloudflare preview
599-
```
600-
601-
It is possible to only populate the cache without any other steps with the `populateCache` command.
602-
603-
```sh
604-
# The target is passed as an option, either `local` or `remote`.
605-
opennextjs-cloudflare populateCache local
606-
```
588+
To populate remote bindings and create a new [version](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/#versions) of your application at the same time, you can use either the [`deploy`](/cloudflare/cli#deploy-command) command or the [`upload`](/cloudflare/cli#upload-command) command. Similarly, the [`preview`](/cloudflare/cli#preview-command) command will populate your local bindings and start a Wrangler dev server.
607589

608590
</Tabs.Tab>
609591
<Tabs.Tab>

pages/cloudflare/cli.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Callout } from "nextra/components";
2+
3+
## `opennextjs-cloudflare` CLI
4+
5+
The Cloudflare adapter provides a `opennextjs-cloudflare` CLI to develop, build, and deploy your application. You should not use `wrangler` commands directly unless documented otherwise or if you know what you are doing.
6+
7+
## commands
8+
9+
`opennextjs-cloudflare` support multiple commands, invoked via `opennextjs-cloudflare <command>`.
10+
11+
The currently supported commands are `build`, `populateCache`, `preview`, `deploy`, and `upload`.
12+
13+
You can list the commands by invoking `pnpm opennextjs-cloudflare` and get help with a given command by invoking `pnpm opennextjs-cloudflare <command> --help`.
14+
15+
Most commands take command specific options (i.e. `pnpm opennextjs-cloudflare build --skipNextBuild --noMinify`) and also accept wrangler options (i.e. `pnpm opennextjs-cloudflare build --config=/path/to/wrangler.jsonc --env=prod`).
16+
17+
### `build` command
18+
19+
It first builds the Next.js application by invoking the `build` script of the `package.json` - which typically execute `next build`. It then runs the Cloudflare specific build step to update the built files to run on the Cloudflare runtime.
20+
21+
### `populateCache` command
22+
23+
It populates the configured [Open Next cache components](/cloudflare/caching) so that caching works at runtime. It can populate the local bindings (`populateCache local`) used during development on your local machine or the remote bindings (`populateCache remote`) used by the deployed application. Note that this command is implicitly called by the `preview`, `deploy`, and `upload` commands so there is no need to explicitly call `populateCache` when one of those is used.
24+
25+
### `preview` command
26+
27+
It starts by populating the local cache and then launches a local development server (via `wrangler dev`) so that you can preview the application locally.
28+
29+
### `deploy` command
30+
31+
It starts by populating the remote cache and then deploys your application to Cloudflare (via `wrangler deploy`). The application will start serving as soon as it is deployed.
32+
33+
### `upload` command
34+
35+
It starts by populating the remote cache and then uploads a version of your application to Cloudflare (via `wrangler upload`). Note that the application will not automatically be served on uploads. See [Gradual deployments](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/gradual-deployments/) to learn more about how to serve an uploaded version.

pages/cloudflare/get-started.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Add the following to the scripts field of your `package.json` file:
134134
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts",
135135
```
136136

137-
- The `build` script must invoke the Next.js build command, it will be invoke by `opennextjs-cloudflare build`.
137+
- The `build` script must invoke the Next.js build command, it will be invoked by [`opennextjs-cloudflare build`](/cloudflare/cli#build-command).
138138
- `npm run preview`: Builds your app and serves it locally, allowing you to quickly preview your app running locally in the Workers runtime, via a single command.
139139
- `npm run deploy`: Builds your app, and then immediately deploys it to Cloudflare.
140140
- `npm run upload`: Builds your app, and then uploads a new [version](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/#versions) of it to Cloudflare.

pages/cloudflare/howtos/dev-deploy.mdx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ initOpenNextCloudflareForDev();
4242

4343
#### Use `opennextjs-cloudflare` to build and test on the Workers runtime
4444

45-
After you've finished iterating on your Next.js application with `next dev`, you can convert it to a Cloudflare Worker by running the `opennextjs-cloudflare build` command. This will generate the Worker code in the `.open-next` directory.
45+
After you've finished iterating on your Next.js application with `next dev`, you can convert it to a Cloudflare Worker by running the [`opennextjs-cloudflare build` command](/cloudflare/cli#build-command). This will generate the Worker code in the `.open-next` directory.
4646

4747
You can then preview the app locally in the Cloudflare Workers runtime.
4848

49-
To preview your worker locally, run the `opennextjs-cloudflare preview` command. This will populate the cache and create a local server that runs your worker in the Cloudflare Workers runtime. Testing your worker is important to ensure that it has been properly built and is working as expected.
49+
To preview your worker locally, run the [`opennextjs-cloudflare preview` command](/cloudflare/cli#preview-command). This will populate the cache and create a local server that runs your worker in the Cloudflare Workers runtime. Testing your worker is important to ensure that it has been properly built and is working as expected.
5050

5151
### Deploy your application to Cloudflare Workers
5252

53-
Both the `deploy` and `upload` commands of `opennextjs-cloudflare` can be used to deploy your application to cloudflare Workers. Both commands will initialize the remote cache and upload your application to the Cloudflare infrastructure.
53+
Both the [`deploy`](/cloudflare/cli#deploy-command) and [`upload`](/cloudflare/cli#upload-command) commands of `opennextjs-cloudflare` can be used to deploy your application to cloudflare Workers. Both commands will initialize the remote cache and upload your application to the Cloudflare infrastructure.
5454

5555
While `deploy` will start serving your application as soon as it is uploaded, `upload` only creates a new version of the application so that you can use [gradual deployments](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/gradual-deployments/).
5656

@@ -76,13 +76,3 @@ In the Build settings:
7676

7777
- The "Build command" should be set to `npx opennextjs-cloudflare build`.
7878
- The "Deploy command" should be set to `npx opennextjs-cloudflare deploy` (or `upload` to use gradual deployments).
79-
80-
<Callout type="info">
81-
The `deploy`, `upload`, and `populateCache` commands of `opennextjs-cloudflare` invoke `wrangler`.
82-
You can pass arguments to `wrangler` by specifying them after `--`:
83-
84-
```sh
85-
opennextjs-cloudflare deploy -- --env=prod
86-
```
87-
88-
</Callout>

0 commit comments

Comments
 (0)