# apply, preset and blocks

> Apply a preset to an existing project, read a preset code, and find the blocks to add.

Source: https://bettersupabase.com/docs/cli/presets

These commands work with [presets](/docs/presets) and the block catalog. To
start a new project from a preset, use
[`init --preset`](/docs/cli/init#starting-from-a-preset).

## apply [#apply]

```bash
pnpm better-supabase apply --preset crm
pnpm better-supabase apply --preset 1pWEF3d578B1iGt16 --dry-run
pnpm better-supabase apply --preset crm --only blocks
```

`apply` edits the config file you have. By default it sets `preset` to the
named preset or the code, replacing the one the config has, so
`defineConfig` expands it into `blocks` and the conventions while your own
keys keep winning. It prints the diff of the config file, then loads the
config again and writes the module files of every block it now holds, as
`better-supabase sql sync` does. `--dry-run` prints the diff and writes
nothing.

| `--only`      | What `apply` changes                                                                         |
| ------------- | -------------------------------------------------------------------------------------------- |
| unset         | `preset`: the preset's blocks and its conventions                                            |
| `blocks`      | `blocks`: the preset's blocks and what they require, listed by name; `preset` stays as it is |
| `conventions` | `preset`: a code with the preset's conventions and no blocks                                 |

A preset that can't install stops `apply` with the reason. When the config
isn't an object literal `apply` can follow, it changes nothing and prints the
`preset` entry to set yourself. Without a config file, `apply` points to
`init --preset`.

## preset [#preset]

```bash
pnpm better-supabase preset decode 1pWEF3d578B1iGt16
pnpm better-supabase preset decode "https://bettersupabase.com/create?preset=1pWEF3d578B1iGt16"
pnpm better-supabase preset info
```

`preset decode` takes a name, a code or a `/create` URL and prints the
conventions, every block the preset installs with the reason it is there,
and anything that can't install, which exits 1. A code from an older
version also lists the fields it predates, which decode at their defaults.

`preset info` reads the `preset` of the config and prints the same, then
how the config differs from it: the blocks it adds (`+`), a casing that
differs, and the preset blocks it gives settings of its own (`~`).

## blocks [#blocks]

```bash
pnpm better-supabase blocks list
pnpm better-supabase blocks list --category crm
pnpm better-supabase blocks view comments
pnpm better-supabase blocks search invoice
```

`blocks list` prints every block by category, and `--category` keeps one
(`foundation`, `collaboration`, `crm`, `work`, `commerce`, `scheduling`,
`ai`, `content`, `operations` or `platform`). `blocks view` prints one
block: what it requires, what it works with, its modes, its client
subpath, the `better-supabase add` command and its registry glue.
`blocks search` matches the name, the title and the description. Each one
reads the same catalog as [/blocks](https://bettersupabase.com/blocks) and
`--json` prints it as data.