Skip to content

Commit 11edde8

Browse files
feat: show prisma CLI output on the docs in the CLI's own colours, in light and dark mode (#9038)
* feat(ui): colour prisma CLI output by the CLI's tones, checked against real captures colorizeTerminalOutput styles plain CLI output with the tones prisma-cli's engine and the ORM's renderers use (palette, rendering, migration graph lanes, focus mode and back-arc colours). Every capture from prisma 8.0.0-rc.39 with ORM 8.0.0-rc.28 is reproduced character by character; rules with no capture are tested by hand against the source. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * feat(ui): a terminal fence language that renders CLI output in the CLI's colours terminal is aliased to plain text for Shiki; transformerTerminalColors wraps each run in a terminal-<tone> span before box drawing runs. Tone classes have light (WCAG AA on white) and dark values through --shiki-light and --shiki-dark. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs: show the migration graph example as a terminal block and remove TerminalOutput The page's worked example becomes a terminal fence with the capture's plain text. The TerminalOutput component, its capture, tests, llm-markdown step and CSS are removed. Agents' Markdown gets terminal fences as text fences. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(ui): bold the app name in prisma deploy's summary, as Composer's deploy command does Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs: show prisma CLI output in terminal blocks, in the CLI's colours 136 fences of prisma CLI output in 43 pages move from text to terminal. Fences of other tools' output, and those whose colours the CLI's source does not determine, stay text. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(ui): leave a terminal block uncoloured when its lines drift, check dark contrast, spread close colours The transformer pairs styled lines with Shiki's by position; if a notation transformer removed a line the counts differ and the block stays plain. The contrast test also checks dark values on the lightest dark code panel. ok/ref and info/color-4 light values move apart. make is no longer a command name: it turned prose such as 'make it optional' cyan. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(ui): register terminal as its own plain grammar instead of a langAlias With langAlias set, fumadocs builds a new Shiki highlighter for every compile instead of sharing one, and the docs dev server failed every page with 'Language bash not found'. An empty grammar passed through langs keeps fumadocs on its shared highlighter, and the transformer still sees the block's language as terminal. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * refactor: rename the terminal fence language to prisma-output terminal read as 'any terminal output'; the colours only fit what the prisma CLI printed. The fence, the module and function names, and the CSS classes (now cli-tone-<tone>) say so. The colouriser's doc names its three source codebases and the releases its rules match. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * test(ui): fail the parallel-compile test when fumadocs stops sharing its highlighter With langAlias restored the old test still passed. It now asserts rehypeCodeOptions has no langAlias and that the shared highlighter is reused with prisma-output and each fence's language loaded; each assertion fails on its own under langAlias. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * test(docs): snapshot the colours of every prisma-output block A page edit or a rule change that alters a block's colours, or leaves a block with none, now fails until the snapshot is accepted. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs(agents): say when a block is prisma-output, bash or text Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs: move commands out of prisma-output blocks Two script echo lines are dropped (the command is already in the block before); the rollbacks page gets an npm block for its command. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * test(docs): find tilde prisma-output fences and sort pages by code point Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs(agents): command fences, prisma dev and deploy output, sessions, and fixing a block that lost its colour Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs(agents): plain snapshot command, script echo lines, and output blocks by tool Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs(github-actions): give the seed command and its output their own blocks Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(ui): keep a table row's own text when it is shorter than the header Rows are cut at the header's column starts into cells and the gaps after them, so the runs always join back into the row. A test checks that every capture's runs join back into its text. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(ui): colour prisma-output lines from the text Shiki left in them The transformer coloured from the raw source, so text an earlier transformer removed would come back. It now colours each line's own text, which also keeps the colours in step with the lines. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * test(docs): skip prisma-output fences shown inside longer fences; accept CRLF after the fence label The snapshot scanner now skips a fence nested in a longer one, and checks that every block's runs join back into its text. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * test(ui): pin that prisma-output handles notation comments as text does Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * docs: colour the missed prisma output blocks; state what notation does in prisma-output; end fences on CRLF pages Converts the dev ready lines, the telemetry first-run notice and the skills staleness notice to prisma-output, and records them as plain. The notation test now states the observed behaviour, with a ts control. The snapshot scanner splits pages on CRLF too. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> --------- Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
1 parent 9012eb8 commit 11edde8

104 files changed

Lines changed: 4220 additions & 451 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/skills/docs-writer/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Better:
103103
> **Initialize Prisma**
104104
> Set up Prisma in your project. This creates a `prisma/` directory with your schema file and a `.env` file for your database connection string.
105105
>
106-
> ```terminal
106+
> ```npm
107107
> npx prisma init
108108
> ```
109109
>
@@ -115,6 +115,7 @@ Better:
115115
- Put the requirement or context before the command, never after.
116116
- Every code block must run or compile as written. No pseudo-code in step-by-step instructions.
117117
- Label code blocks with the target file path when the reader edits or creates a file.
118+
- Put a command the reader runs in an `npm` block when it starts with `npx` or `npm`, otherwise in a `bash` block. Put output the `prisma` CLI printed, copied unchanged, in a `prisma-output` block after it: the site colours it the way the CLI does. That includes `prisma dev` and `prisma deploy` output; deploy-engine lines mixed into it stay plain. Put any other tool's output (npm, Next.js, Docker, output that is only the deploy engine's) in a `text` block. `apps/docs/AGENTS.md` has the details.
118119
- Prefer one complete, real example over an abstract description of options. Show the common case; link to the reference for the rest.
119120
- State a limitation where the reader will hit it, inline with the relevant step, not in a footnote.
120121
- Link the first mention of a concept the reader may not know. Don't re-link it every time.

‎apps/docs/AGENTS.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ What follows when a tool does the wrong thing while you write or test a page:
3939

4040
This does not cover three things, which the docs do explain: a limit of software Prisma does not own (PostgreSQL, a MySQL server setting, Node.js, Vercel), behaviour that is designed and intended, and a feature that does not exist yet ("X is not supported yet"). If you cannot tell a defect from intended behaviour, read the tool's source and design docs, then ask.
4141

42+
## Code blocks of command output
43+
44+
A `prisma-output` block shows output the `prisma` CLI printed, and the site colours it the way the CLI colours it in a terminal. The colours come from rules copied from the CLI's source (`packages/ui/src/mdx/prisma-output-colors.ts`), so they only fit text the `prisma` CLI wrote, copied unchanged.
45+
46+
Use `prisma-output` for the output of a `prisma` command: results starting `✔`, `✓`, `✘ [CODE]`, `⚠`, `ℹ` or `→`, `│ key: value` headers, tables, migration graphs and `orm init` summaries. `prisma dev` and `prisma deploy` count too: their summaries, their `Address`/`Deployed` table and their `[CODE]` errors are the CLI's own. Lines the deploy engine passes through (Alchemy's messages and plan lines) are not, but a block that mixes them with the CLI's lines is still `prisma-output`, and the engine lines stay plain.
47+
48+
Use `text` for everything else: other tools' output (npm, Next.js, Docker, create-* scaffolders), `prisma` output that another tool prefixed or reflowed (turbo, `bun run --filter`, docker compose), output that is only the deploy engine's, and output an older release printed in a shape the CLI no longer prints. The CLI's rules would colour those wrongly.
49+
50+
Put the command the reader runs in its own block before the output: an `npm` block when it starts with `npx` or `npm` (the site offers it for pnpm, yarn and bun too), otherwise `bash`. When you copy a terminal session with `$` prompts, split it into that command block and an output block, in the language the command's tool calls for: `prisma-output` only when the command is `prisma`. When pnpm or bun echoes a `$ …` line for a script whose command is already in the block before, drop the echo line and keep the rest as `prisma-output`. A block in which another tool prefixes every line stays `text`.
51+
52+
`src/lib/prisma-output-colors.test.ts` snapshots the colours of every `prisma-output` block. If a block loses its colour or the test fails, check the fence is named `prisma-output`, and whether a newer `prisma` release printed the output in a different shape; if so, copy it again from the current release, or make it `text`. Run the test from `apps/docs`:
53+
54+
```bash
55+
node --import tsx --import ./test/register-hooks.mjs --test src/lib/prisma-output-colors.test.ts
56+
```
57+
58+
When the new colours in its diff are right, accept them by running the same command with `UPDATE_PRISMA_OUTPUT_SNAPSHOT=1` in front.
59+
4260
## Generated content
4361

4462
1. `content/docs/rest-api/endpoints/` and `public/prisma-rest-api.postman_collection.json` are generated. Never hand-edit; run `pnpm generate:rest-api-docs`.

‎apps/docs/content/docs/(index)/prisma-orm/add-to-existing-project/postgresql.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ The first line loads `.env`, so every file that imports `db` reads `DATABASE_URL
9090
npx prisma contract infer --output ./src/prisma/contract.prisma
9191
```
9292

93-
```text no-copy
93+
```prisma-output no-copy
9494
✔ Connecting to database...
9595
✔ Introspecting database schema...
9696
Overwriting existing file: src/prisma/contract.prisma
@@ -220,7 +220,7 @@ You can ignore these warnings on a contract that `contract infer` wrote. They ar
220220
npx prisma db sign
221221
```
222222

223-
```text no-copy
223+
```prisma-output no-copy
224224
✔ Connecting to database...
225225
✔ Introspecting database schema
226226
✔ Signing database
@@ -235,7 +235,7 @@ npx prisma db sign
235235

236236
A table or a column that the database has and the contract does not declare is not a problem. When something the contract declares is missing from the database, `db sign` writes nothing and exits with code 4. For example, with a `phone` field in the `User` model and no `phone` column in the table:
237237

238-
```text no-copy
238+
```prisma-output no-copy
239239
✘ app: not signed, the schema does not satisfy its contract
240240
└─ ✘ missing: database/public/user/column:phone
241241
@@ -355,7 +355,7 @@ npx prisma contract emit
355355
npx prisma migration plan --name add_user_phone
356356
```
357357

358-
```text no-copy
358+
```prisma-output no-copy
359359
│ contract: src/prisma/contract.json
360360
│ migrations: migrations/app
361361
│ name: add_user_phone
@@ -392,7 +392,7 @@ Apply the migration:
392392
npx prisma db migrate
393393
```
394394

395-
```text no-copy
395+
```prisma-output no-copy
396396
✔ Running migration plan across spaces
397397
│ migrations: migrations
398398
│ database: postgresql://****:****@127.0.0.1:55432/legacy

‎apps/docs/content/docs/(index)/prisma-orm/from-scratch.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ model User {
107107
npx prisma contract emit
108108
```
109109

110-
```text
110+
```prisma-output
111111
✔ Resolving contract source...
112112
✔ Emitting contract...
113113
│ contract: prisma/contract.json
@@ -123,7 +123,7 @@ profileHash: acce1918cc027c4643d54a338c3244818bcb05a68c5bf3bee655dc1ed12e8310
123123
npx prisma db init
124124
```
125125

126-
```text
126+
```prisma-output
127127
✔ Introspecting database schema
128128
✔ Planning migration
129129
✔ Initialising database across spaces
@@ -230,7 +230,7 @@ npx prisma contract emit
230230
npx prisma migration plan --name add_user_phone
231231
```
232232

233-
```text
233+
```prisma-output
234234
✔ Planned baseline (3 operation(s)) + 1 operation(s)
235235
migrations/app/20261120T1014_baseline
236236
├─ Create schema "public"
@@ -262,7 +262,7 @@ Apply the migration with `db migrate`, which also records in the `db` ref that y
262262
npx prisma db migrate
263263
```
264264

265-
```text
265+
```prisma-output
266266
✔ Applied 1 migration(s) (1 operation(s)) across 1 contract space(s)
267267
App space
268268
├─ Add column "phone" to "User"
@@ -294,7 +294,7 @@ Check that the migration files on disk and the database agree:
294294
npx prisma migration status
295295
```
296296

297-
```text
297+
```prisma-output
298298
○ 58a4c67 @contract @db (db)
299299
│↑ 20261120T1015_add_user_phone 20f81b5 → 58a4c67 1 ops ✓ applied
300300
○ 20f81b5

‎apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/mongodb.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ npx prisma@latest orm init --yes --target mongodb --authoring psl --write-env
3939

4040
The command installs the packages, writes the files, and ends with the summary below. In `package.json`, it adds the packages with their current version numbers, and a `contract:emit` script that runs `prisma contract emit`. If your project already has a `tsconfig.json` or a `.gitignore`, the command edits that file and keeps the rest of it.
4141

42-
```text no-copy
42+
```prisma-output no-copy
4343
│ target: mongodb
4444
│ authoring: psl
4545
│ schema: src/prisma/contract.prisma
@@ -136,7 +136,7 @@ Run `contract emit` after every change to the contract. It takes the place of `p
136136
npx prisma contract emit
137137
```
138138

139-
```text no-copy
139+
```prisma-output no-copy
140140
✔ Resolving contract source...
141141
✔ Emitting contract...
142142
│ contract: src/prisma/contract.json
@@ -156,7 +156,7 @@ The command writes `contract.json` and `contract.d.ts` next to the contract. Com
156156
npx prisma db init
157157
```
158158

159-
```text no-copy
159+
```prisma-output no-copy
160160
✔ Introspecting database schema
161161
✔ Planning migration
162162
✔ Initialising database across spaces
@@ -258,7 +258,7 @@ npx prisma contract emit
258258
npx prisma migration plan --name add_user_phone
259259
```
260260

261-
```text no-copy
261+
```prisma-output no-copy
262262
│ contract: src/prisma/contract.json
263263
│ migrations: migrations/app
264264
│ name: add_user_phone
@@ -285,7 +285,7 @@ Apply the migration:
285285
npx prisma db migrate
286286
```
287287

288-
```text no-copy
288+
```prisma-output no-copy
289289
✔ Running migration plan across spaces
290290
│ migrations: migrations
291291
│ database: mongodb://127.0.0.1:27129/app1

‎apps/docs/content/docs/(index)/prisma-orm/quickstart/existing-app/postgresql.mdx‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ npx prisma@latest orm init --yes --target postgres --authoring psl --write-env
3939

4040
The command installs the packages, writes the files, and ends with the summary below. In `package.json`, it adds the packages with their current version numbers, and a `contract:emit` script that runs `prisma contract emit`. If your project already has a `tsconfig.json` or a `.gitignore`, the command edits that file and keeps the rest of it.
4141

42-
```text no-copy
42+
```prisma-output no-copy
4343
│ target: postgres
4444
│ authoring: psl
4545
│ schema: src/prisma/contract.prisma
@@ -136,7 +136,7 @@ Run `contract emit` after every change to the contract. It takes the place of `p
136136
npx prisma contract emit
137137
```
138138

139-
```text no-copy
139+
```prisma-output no-copy
140140
✔ Resolving contract source...
141141
✔ Emitting contract...
142142
│ contract: src/prisma/contract.json
@@ -156,7 +156,7 @@ The command writes `contract.json` and `contract.d.ts` next to the contract. Com
156156
npx prisma db init
157157
```
158158

159-
```text no-copy
159+
```prisma-output no-copy
160160
✔ Introspecting database schema
161161
✔ Planning migration
162162
✔ Initialising database across spaces
@@ -245,7 +245,7 @@ npx prisma contract emit
245245
npx prisma migration plan --name add_user_phone
246246
```
247247

248-
```text no-copy
248+
```prisma-output no-copy
249249
│ contract: src/prisma/contract.json
250250
│ migrations: migrations/app
251251
│ name: add_user_phone
@@ -273,7 +273,7 @@ Apply the migration:
273273
npx prisma db migrate
274274
```
275275

276-
```text no-copy
276+
```prisma-output no-copy
277277
✔ Running migration plan across spaces
278278
│ migrations: migrations
279279
│ database: postgresql://****:****@127.0.0.1:55432/app1

‎apps/docs/content/docs/cli/db-migrate.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ When no sequence of the migrations on disk leads from the state the database is
113113

114114
You edited the contract, ran `contract emit`, and then ran `db migrate`. The target is your new contract, and no migration ends at it yet. The error gives the state the database is in as a hash, and it calls a migration an edge. These are its first lines:
115115

116-
```text
116+
```prisma-output
117117
✘ [MIGRATION.PATH_UNREACHABLE] Current contract has no planned migration path
118118
why: No migration edge connects "<current hash>" to the target "<target hash>" in contract space "app". The on-disk migration graph does not join the two, and migrate replays existing edges — it never invents one.
119119
→ Plan the missing edge: prisma migration plan --from <current hash>
@@ -171,7 +171,7 @@ With `--json`, the `error` object of the result has a `meta` object that holds `
171171

172172
Each operation checks the database before and after it runs, as [How migrations work](/orm/migrations/how-migrations-work#every-operation-checks-itself) explains. When a check fails, `db migrate` stops and its `why` says which check failed and, when the check names one object, what the database already has or lacks:
173173

174-
```text
174+
```prisma-output
175175
✘ [MIGRATION.PRECHECK_FAILED] Operation table.user failed during precheck: ensure table "user" does not exist
176176
why: Before operation table.user runs, it checks: ensure table "user" does not exist. That check failed: the database already has table "user". The failed apply changed nothing.
177177
```

‎apps/docs/content/docs/cli/dev.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ With `--detach`, `dev` prints the same `ready` line and service URLs as a foregr
6767
npx prisma dev url my-app.gateway
6868
```
6969

70-
```text no-copy
70+
```prisma-output no-copy
7171
✔ The service my-app.gateway is running at http://localhost:3001
7272
```
7373

‎apps/docs/content/docs/cli/emulator.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ npx prisma emulator list --json
3131
npx prisma emulator list
3232
```
3333

34-
```text no-copy
34+
```prisma-output no-copy
3535
✔ Service emulator at http://127.0.0.1:4304
3636
└─ svc_56b2c1618f6488d2 http://localhost:3001 running my-app.gateway in /Users/ada/my-app
3737
✔ Database emulator at http://127.0.0.1:4305

‎apps/docs/content/docs/cli/migration-plan.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ npx prisma migration plan --name age_to_int --convert User.age --backfill User.d
172172

173173
If the storage part of the contract did not change, `migration plan` writes nothing and prints `✔ No changes detected`; with `--json`, the result's `summary` is `No changes detected between contracts`. That is not an error, and there is nothing to do. If the storage part changed but the database needs no change, `migration plan` writes a migration with no operations and names what changed:
174174

175-
```text
175+
```prisma-output
176176
⚠ Planned 0 operation(s). The storage the contract describes changed, but the database needs no operation for it, so the migration has none. What changed: table "public.user".
177177
```
178178

0 commit comments

Comments
 (0)