cf-pages-cli

Crates.iocf-pages-cli
lib.rscf-pages-cli
version0.2.1
sourcesrc
created_at2023-04-25 13:46:15.852964
updated_at2023-04-25 15:48:29.468764
descriptionA simple command line utility for managing Cloudflare Pages projects
homepage
repositoryhttps://github.com/xJonathanLEI/cf-pages-cli
max_upload_size
id848499
size61,434
Jonathan LEI (xJonathanLEI)

documentation

README

cf-pages-cli

Command line utility for managing Cloudflare Pages projects

crates-badge

What is 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.

Installation

With cargo installed, install from crates.io:

cargo install --locked --version 0.2.1 cf-pages-cli

Usage

Synchronize variables

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

Generate .env files

The 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.

License

Licensed under either of

at your option.

Commit count: 14

cargo fmt