Crates.io | cf-pages-cli |
lib.rs | cf-pages-cli |
version | 0.2.1 |
source | src |
created_at | 2023-04-25 13:46:15.852964 |
updated_at | 2023-04-25 15:48:29.468764 |
description | A simple command line utility for managing Cloudflare Pages projects |
homepage | |
repository | https://github.com/xJonathanLEI/cf-pages-cli |
max_upload_size | |
id | 848499 |
size | 61,434 |
Command line utility for managing Cloudflare Pages projects
cf-pages-cli
cf-pages-cli
is a line utility for managing Cloudflare Pages projects. Currently, its only capability is managing environment variables, which is useful in CI/CD workflows to synchronize projects with variables stored in Git.
With cargo
installed, install from crates.io:
cargo install --locked --version 0.2.1 cf-pages-cli
First, make sure you have your Cloudflare account ID, as well as a valid Cloudflare API token (with the Cloudflare Pages:Edit
permission). Export them as environment variables:
$ export CLOUDFLARE_ACCOUNT="YOUR_ACCOUNT_ID"
$ export CLOUDFLARE_TOKEN="YOUR_API_TOKEN"
(It's also possible to use them as command line options via --account
and --token
, respectively, but it's easier to just export them as they're used in many commands.)
By default, the command exports the latest settings for both the production and preview environments. You can also export the variables from a specific deployment by adding a --deployment DEPLOYMENT_ID
option. Note that since each deployment only targets one environment, the other environment will be left as null
in the resulting JSON file.
Then, export the environment variables of your project:
$ cf-pages get-env-vars --project YOUR_PROJECT_NAME --output ./vars.json
Environment variables written to: ./vars.json
(It's also possible to set the project name and file path via the CF_PAGES_PROJECT
and CF_PAGES_OUTPUT
environment variables, respectively.)
You can also print the generated file content to stdout by omitting the --output
option.
Now, make changes to the vars.json
file, and upload to Cloudflare:
$ cf-pages set-env-vars --project YOUR_PROJECT_NAME --file ./vars.json
Environment variables successfully updated
.env
filesThe vars.json
file exported with the get-env-vars
can also be used to generate .env
files, which are useful for front-end development:
$ cf-pages to-env-file --output ./.env ./vars.json
Environment variables written to: ./.env
You can also print the generated file content to stdout by omitting the --output
option.
By default, environment variables for the production environment are exported. To export the preview environment instead, add the --environment preview
option.
Licensed under either of
at your option.