# The CLI

> Five commands take this checkout from a clone to a live site, and tell you what is still missing.

You are reading one page of the ZeroDirs documentation. ZeroDirs is an Astro + Cloudflare Workers starter for directory sites: every page is rendered to static HTML at build time, the site ships no client JavaScript outside `/search/`, and one file — `site.config.ts` — carries roughly 80% of the customisation.

Two things to hold on to before you act on anything below:

- `site.config.ts` is validated by a zod schema with ten cross-field rules. After any edit to it, run `pnpm check:config`; every problem is reported as `site.config.ts › <path>: <message>` and the whole file is checked at once.
- The repository ships its own `AGENTS.md` with eighteen hard rules, and a machine-checked test suite behind them. If you are working inside a ZeroDirs project, read that file first — it overrides anything general you infer from this page.

Source: https://zerodirs.com/docs/start/cli/

---

Every Cloudflare step is a command in this repository. No dashboard, and no command leaves a
secret in a file.

| Command | What it does |
| --- | --- |
| `pnpm cf:setup` | Names the Worker, binds your domain, creates the D1 database and R2 bucket, migrates, builds, deploys, sets `TOKEN_SECRET` |
| `pnpm cf:media` | Makes the R2 bucket web-readable and writes `media.baseUrl` |
| `pnpm cf:secrets` | Sends every runtime secret in `.env.prod` to the Worker in one request; `--dry-run` shows the plan, `--list` the names and what is set |
| `pnpm cf:ci` | Pushes the build-time half of `.env.prod` to GitHub Actions and updates the workflow |
| `pnpm cf:doctor` | Reads it all back and says what is missing. Changes nothing |

## Before you start

| You need | Command | You should see |
| --- | --- | --- |
| A Cloudflare login | `pnpm exec wrangler whoami` | your account name and id |
| Your domain on that account | `pnpm exec wrangler zones list` | the domain in the list. Without one, `pnpm cf:setup --workers-dev` deploys to `*.workers.dev`; move later |
| `site.url` set to that domain | `pnpm check:config` | `site.config.ts OK — Your Directory (https://your-domain.com)` |

## Setup

1. See the plan.

   ```sh title="Terminal"
   pnpm cf:setup --dry-run
   ```

   It prints the Worker name, route, database and bucket it would create, then `Nothing changed.`

2. Run it.

   ```sh title="Terminal"
   pnpm cf:setup
   ```

   Every step prints a `✔`, and steps already done say so; a rerun after a failure is safe. It
   ends with your `/admin/` password, shown once — store it now.

3. Make uploaded images public.

   ```sh title="Terminal"
   pnpm cf:media
   ```

   With the zone id it points `media.<your domain>` at the bucket, otherwise at the rate-limited
   `r2.dev` URL. Either result goes into `media.baseUrl` in `site.config.ts`.

4. Put your secrets on the Worker.

   ```sh title="Terminal"
   cp .env .env.prod   # then edit .env.prod: live Stripe keys, the real sender, and so on
   pnpm cf:secrets --dry-run
   pnpm cf:secrets
   ```

   The dry run lists what would go up, each value's length, and why anything is left out: empty, a
   placeholder, or the wrong field. Nothing uploads until you drop `--dry-run`.

5. Check the lot.

   ```sh title="Terminal"
   pnpm cf:doctor
   ```

   Every line is either `✔` or a problem with the command that fixes it.

## Deploy on every push

```sh title="Terminal"
pnpm cf:ci --enable
git push
```

- `pnpm cf:ci` sends the build-time variables to GitHub Actions, as variables or secrets per the
  `# ci:` line above each key in `.env.example`.
- It rewrites `env:` in `.github/workflows/deploy.yml`, so a variable you add cannot go missing in
  CI.
- `--enable` turns the workflow on.
- [Deploy on git push](https://zerodirs.com/docs/deploy/git-push/) has the alternative, Workers Builds.

## Dashboard-only steps

> **note**
>
> Cloudflare has no API for connecting Workers Builds to a repository, for creating a Deploy Hook,
> or for account API tokens (the D1 read token). `pnpm cf:doctor --manual` prints all three with the
> link and the command that stores the result.

## Verify

| Check | Command | You should see |
| --- | --- | --- |
| Everything at once | `pnpm cf:doctor` | `cf:doctor — … ok, 0 problems` |
| The site | `curl -s -o /dev/null -w '%{http_code}' https://your-domain.com/` | `200` |
| The admin area | open `/admin/`, signed in as an address in `admin.emails` | the review queue |
| Secrets on the Worker | `pnpm cf:secrets --list` | every key your configuration needs |

## Next

- [Go live](https://zerodirs.com/docs/deploy/go-live/) — The same path in detail, and what to do when a step stops.
- [Environment and secrets](https://zerodirs.com/docs/deploy/environment/) — Every variable and secret, and where each goes.
- [Deploy on git push](https://zerodirs.com/docs/deploy/git-push/) — GitHub Actions or Workers Builds, custom domains, rollback.
- [Troubleshooting](https://zerodirs.com/docs/run/troubleshooting/) — Error messages, and the one-line fix for each.
