excalideck 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +12 -0
- package/.claude-plugin/plugin.json +11 -0
- package/AGENTS.md +63 -0
- package/LICENSE +21 -0
- package/README.md +163 -2
- package/bin/excalideck +2 -0
- package/cli/doctor.mjs +130 -0
- package/cli/main.mjs +394 -0
- package/cli/media.mjs +118 -0
- package/cli/paths.mjs +24 -0
- package/cli/register.mjs +4 -0
- package/cli/resolve-hook.mjs +9 -0
- package/cli/serve.mjs +77 -0
- package/cli/server.mjs +68 -0
- package/examples/snapline/build.mjs +181 -0
- package/examples/snapline/snapline.excalidraw +13141 -0
- package/lib/excalideck.mjs +267 -0
- package/package.json +60 -4
- package/player/THIRD_PARTY.md +5 -0
- package/player/fonts/Excalifont-Latin.woff2 +0 -0
- package/player/fonts/Virgil.woff2 +0 -0
- package/player/index.html +63 -0
- package/player/player.js +617 -0
- package/player/vendor/LICENSE-roughjs +21 -0
- package/player/vendor/rough.js +1 -0
- package/skills/excalideck/SKILL.md +142 -0
- package/skills/excalideck/api.md +59 -0
- package/src/check.js +158 -0
- package/src/contract/busy-client.js +93 -0
- package/src/contract/exit-codes.js +28 -0
- package/src/contract/health.js +37 -0
- package/src/contract/install-method.js +83 -0
- package/src/contract/output.js +83 -0
- package/src/contract/runtime-file.js +59 -0
- package/src/contract/semver.js +101 -0
- package/src/metrics.js +4 -0
- package/src/scene.js +187 -0
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "excalideck",
|
|
3
|
+
"description": "excalideck: animated hand-drawn architecture slide decks",
|
|
4
|
+
"owner": { "name": "Ed Spencer", "url": "https://github.com/edspencer" },
|
|
5
|
+
"plugins": [
|
|
6
|
+
{
|
|
7
|
+
"name": "excalideck",
|
|
8
|
+
"source": "./",
|
|
9
|
+
"description": "Build and present animated, hand-drawn architecture slide decks from Excalidraw frames"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "excalideck",
|
|
3
|
+
"displayName": "excalideck",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"description": "Build and present animated, hand-drawn architecture slide decks: Excalidraw frames as slides, with shapes that morph, zoom and draw themselves between them.",
|
|
6
|
+
"author": { "name": "Ed Spencer", "url": "https://github.com/edspencer" },
|
|
7
|
+
"homepage": "https://edspencer.github.io/excalideck/",
|
|
8
|
+
"repository": "https://github.com/edspencer/excalideck",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": ["excalidraw", "slides", "presentation", "architecture", "diagrams"]
|
|
11
|
+
}
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# excalideck: working conventions
|
|
2
|
+
|
|
3
|
+
## Layout
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
player/ the presenter: index.html + player.js (ES module, canvas + rough.js), fonts, vendor
|
|
7
|
+
src/scene.js shared by player and CLI: load .excalidraw → slides, element keys, match() between slides
|
|
8
|
+
src/check.js layout lint + transition report (pure Node)
|
|
9
|
+
src/metrics.js measured glyph widths for the bundled fonts, so Node can size text without a canvas
|
|
10
|
+
src/contract/ files copied from cli-contract (see below) — don't edit them except to re-copy
|
|
11
|
+
lib/ the builder library (Deck / Frame)
|
|
12
|
+
cli/ the `excalideck` command: main.mjs (parsing + dispatch), serve, server, media, doctor, paths
|
|
13
|
+
skills/ the Claude Code skill (SKILL.md + api.md), the main way people use this
|
|
14
|
+
examples/ snapline/build.mjs → snapline.excalidraw (the demo, a template, and `serve`'s fallback)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- `npm test` runs the tests. `npm run build:example && npm run check:example` must stay at 0 errors, 0 warnings.
|
|
18
|
+
- The player is served from the repo root (GitHub Pages serves `main` at `/`), so `player/` imports `../src/`.
|
|
19
|
+
- Matching logic lives only in `src/scene.js`. If the player's behaviour changes, `check` should report it the same way.
|
|
20
|
+
- Node built-ins only at runtime. Playwright is a devDependency, and only `render` and `record` use it; they say so
|
|
21
|
+
and exit 1 when it's missing, rather than making it a dependency of the whole tool.
|
|
22
|
+
- `claude plugin validate .` checks the plugin and marketplace manifests.
|
|
23
|
+
|
|
24
|
+
## The CLI contract
|
|
25
|
+
|
|
26
|
+
excalideck follows [cli-contract](https://github.com/edspencer/cli-contract) **1.0**. `cli-contract.json` lists
|
|
27
|
+
every check; `npx cli-conformance` runs them. The reference files in `src/contract/` are copies, translated from
|
|
28
|
+
TypeScript to JavaScript because excalideck has no build step. Each keeps a header naming the file and the contract
|
|
29
|
+
version it came from. **Fix them upstream first**, then re-copy.
|
|
30
|
+
|
|
31
|
+
What excalideck does, beyond its own commands:
|
|
32
|
+
|
|
33
|
+
- `serve` is the foreground name, and bare `excalideck` serves. With no deck named it takes the one `.excalidraw`
|
|
34
|
+
file in the folder; with several it's a usage error; with none it serves the bundled example, so `npx excalideck`
|
|
35
|
+
shows something.
|
|
36
|
+
- `--version`/`-v`, `--help`/`-h`, and `<command> --help`. A flag a command can't act on is a usage error (exit 2)
|
|
37
|
+
that names the command that *does* take it.
|
|
38
|
+
- Exit codes: the shared table. `serve`'s first stdout line is `excalideck <version>: <url>`, `-q` prints only that.
|
|
39
|
+
- `GET /api/health` and `GET /api/busy`, neither needing auth. `~/.excalideck/runtime.json` (0600, atomic) is how
|
|
40
|
+
`busy` finds a running instance; it's removed on a clean exit.
|
|
41
|
+
- `busy` and `doctor`, both with `--json`.
|
|
42
|
+
|
|
43
|
+
### What's left out, and why
|
|
44
|
+
|
|
45
|
+
- **`service install|uninstall|start|stop|restart|status|logs`.** excalideck is run for a talk and stopped after
|
|
46
|
+
it. A presenter that starts at login would serve a deck nobody is looking at, and `serve` takes under a second
|
|
47
|
+
to start. There is no unit, so `service status`'s exit 4 has nothing to report. If excalideck ever grows a
|
|
48
|
+
reason to run unattended, this is the first thing to add; the contract's `reference/service/` has the code.
|
|
49
|
+
- **`update`, for now.** excalideck is published to npm (RELEASING.md), so a global npm install could update itself,
|
|
50
|
+
but the command isn't written yet. `doctor` reports the update check as skipped rather than pretending. Adding it
|
|
51
|
+
means copying the contract's `reference/update/`, then turning on the opt-in `update-*` checks in
|
|
52
|
+
`cli-contract.json`. Until then: `npm install -g excalideck@latest`.
|
|
53
|
+
- **`--host`.** `serve` listens on 127.0.0.1 only. A deck is read off this machine's disk and shown on this
|
|
54
|
+
machine's screen, and binding wider would need the allowed-host guard Localidraw has, for no use anyone has asked
|
|
55
|
+
for. The player sends nothing anywhere.
|
|
56
|
+
- **`busy` is never true.** Presenting holds nothing a restart would lose: the deck is read from disk on each
|
|
57
|
+
request and nothing is written. `busy` answers `{ busy: false, counts: {} }` so scripts can ask every one of
|
|
58
|
+
these tools the same question and get a straight answer.
|
|
59
|
+
- **Log rotation and `<home>/logs/`.** There's no service writing a log.
|
|
60
|
+
|
|
61
|
+
## Writing
|
|
62
|
+
|
|
63
|
+
Plain, direct, British spelling, short sentences. Say what happens, not what might.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ed Spencer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,164 @@
|
|
|
1
|
-
#
|
|
1
|
+
# excalideck
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Present Excalidraw files as slide decks where the diagram morphs from one slide to the next.**
|
|
4
|
+
Boxes glide to new positions, open up into the parts inside them, draw themselves in, and clone out.
|
|
5
|
+
Arrows stay attached throughout. It's made for walking an audience through software architecture
|
|
6
|
+
from the outside in.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
**[▶ Try it in your browser](https://edspencer.github.io/excalideck/)** (press → to advance, O for the
|
|
11
|
+
overview, ? for keys), or [watch the whole 30-second demo](media/snapline.mp4).
|
|
12
|
+
|
|
13
|
+
Every slide is a **frame** in one ordinary `.excalidraw` file, so you can still open and edit it at
|
|
14
|
+
[excalidraw.com](https://excalidraw.com). excalideck works out which shapes on one slide are the "same"
|
|
15
|
+
shapes on the next, and animates the difference.
|
|
16
|
+
|
|
17
|
+
| | |
|
|
18
|
+
|---|---|
|
|
19
|
+
| **Drill down**: a box zooms open into a region with the same name; everything else flies past<br><img src="media/drilldown.gif" width="420"> | **Draw on**: outlines sketch themselves in, and arrows wait for both their boxes<br><img src="media/draw.gif" width="420"> |
|
|
20
|
+
| **Highlight a path**: everything else dims while one flow turns red<br><img src="media/highlight.gif" width="420"> | **Clone out**: three workers split off from the original one<br><img src="media/clone.gif" width="420"> |
|
|
21
|
+
| **Camera**: fly across the canvas to a frame drawn somewhere else<br><img src="media/camera.gif" width="420"> | **The source**: one Excalidraw file with ten frames<br><img src="media/snapline-in-excalidraw.png" width="420"> |
|
|
22
|
+
|
|
23
|
+
## Make decks with Claude Code
|
|
24
|
+
|
|
25
|
+
excalideck ships as a Claude Code plugin: a skill that teaches Claude how to plan an outside-in talk, lay out
|
|
26
|
+
clean diagrams, and check its own work, plus the `excalideck` command.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
claude plugin marketplace add edspencer/excalideck
|
|
30
|
+
claude plugin install excalideck@excalideck
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then ask for what you want:
|
|
34
|
+
|
|
35
|
+
> *Make a 7-slide excalideck talk explaining how our checkout service works: start with the customer and
|
|
36
|
+
> the system as one box, open it up into its services, follow an order through, then drill into the
|
|
37
|
+
> payments service.*
|
|
38
|
+
|
|
39
|
+
Claude writes a short builder script, runs `excalideck build` to generate the deck and lint it (overlapping
|
|
40
|
+
boxes, labels that don't fit, arrows cutting through boxes, and a report of what every transition will
|
|
41
|
+
morph), renders the slides to PNG to look at them, and hands you `excalideck serve talk.excalidraw`.
|
|
42
|
+
|
|
43
|
+
**Nothing leaves your machine.** The builder, checker and player all run locally, and the hosted player reads
|
|
44
|
+
dropped files in your browser without uploading them. That makes it fine for confidential architecture.
|
|
45
|
+
|
|
46
|
+
## Make decks by hand in Excalidraw
|
|
47
|
+
|
|
48
|
+
1. Draw each slide inside a **frame** (frame tool, `F`), and start each frame's name with a number: `01 Title`, `02 Overview`.
|
|
49
|
+
2. For the next step, **duplicate the frame** (Ctrl/Cmd+D) and change the copy: move boxes, add some, recolour, dim.
|
|
50
|
+
3. Optionally put **tags** in the frame name to choose the transition into it: `05 Inside Payments [zoom pop]`.
|
|
51
|
+
4. Drag the file onto the [player](https://edspencer.github.io/excalideck/), or run `excalideck serve deck.excalidraw`.
|
|
52
|
+
|
|
53
|
+
### What counts as "the same shape"
|
|
54
|
+
| Element | Matched across slides by |
|
|
55
|
+
|---|---|
|
|
56
|
+
| Box, ellipse or diamond with text | its label (case-insensitive), even if the shape type changes |
|
|
57
|
+
| Standalone text | identical text |
|
|
58
|
+
| Arrow | the labels at both ends. If only one end matches, it **re-attaches** (`User → Shop` becomes `User → API`) |
|
|
59
|
+
| Extra copies of a label | they **clone out** of the original |
|
|
60
|
+
| Unlabelled shape | same type, in the same place |
|
|
61
|
+
|
|
62
|
+
A box whose label matches a **region** on the next slide grows into it. That's the drill-down.
|
|
63
|
+
|
|
64
|
+
### Tags
|
|
65
|
+
| Transition | | Appear style | |
|
|
66
|
+
|---|---|---|---|
|
|
67
|
+
| `morph` *(default)* | matched shapes glide, resize and recolour | `fade` *(default)* | fade in |
|
|
68
|
+
| `zoom` | camera dives into (or out of) the shape that changes size most | `draw` | sketch in, then fill |
|
|
69
|
+
| `camera` | fly across the canvas to the frame | `pop` | scale up with a little overshoot |
|
|
70
|
+
| `fade` | cross-fade | `rise` | drift up |
|
|
71
|
+
| `cut` | instant | | |
|
|
72
|
+
|
|
73
|
+
Also `slow`, `fast` and `nostagger`.
|
|
74
|
+
|
|
75
|
+
## Write decks as code
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
// talk.mjs: build with `excalideck build talk.mjs`
|
|
79
|
+
import { Deck } from "excalideck";
|
|
80
|
+
|
|
81
|
+
const deck = new Deck();
|
|
82
|
+
|
|
83
|
+
let f = deck.frame("Overview", { appear: "draw" });
|
|
84
|
+
f.title("Overview");
|
|
85
|
+
const user = f.box("Customer", { x: 140, y: 400, shape: "ellipse", color: "orange" });
|
|
86
|
+
const shop = f.box("Shop", { x: 640, y: 380, w: 320, h: 140, size: 32 });
|
|
87
|
+
f.arrow(user, shop, { label: "orders" });
|
|
88
|
+
|
|
89
|
+
f = deck.frame("Inside the shop", { transition: "zoom", appear: "pop" });
|
|
90
|
+
f.title("Inside the shop");
|
|
91
|
+
const user2 = f.box("Customer", { x: 40, y: 400, shape: "ellipse", color: "orange" });
|
|
92
|
+
f.region("Shop", { x: 300, y: 160, w: 860, h: 600 }); // same label → the box opens into this
|
|
93
|
+
const web = f.box("Storefront", { x: 360, y: 410 });
|
|
94
|
+
const api = f.box("Orders API", { x: 640, y: 410, color: "green" });
|
|
95
|
+
const db = f.box("Orders DB", { x: 640, y: 590, shape: "ellipse", color: "violet" });
|
|
96
|
+
f.arrow(user2, web); f.arrow(web, api); f.arrow(api, db);
|
|
97
|
+
|
|
98
|
+
deck.save("talk.excalidraw");
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Boxes size themselves to their labels using the real font metrics. Arrows are bound to their shapes. The output
|
|
102
|
+
is deterministic, so a talk lives happily in git. The full API is in [skills/excalideck/api.md](skills/excalideck/api.md),
|
|
103
|
+
and [examples/snapline/build.mjs](examples/snapline/build.mjs) is the complete demo, written as a template.
|
|
104
|
+
|
|
105
|
+
## Command line
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm install -g excalideck # or: npx excalideck, or use the plugin, which puts it on PATH
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Command | |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `excalideck new talk` | starter script `talk.mjs` + `talk.excalidraw` |
|
|
114
|
+
| `excalideck build talk.mjs` | run the script, then check the result |
|
|
115
|
+
| `excalideck dev talk.mjs` | rebuild and check on save, and serve with live reload |
|
|
116
|
+
| `excalideck check deck.excalidraw` | layout problems per slide + what each transition will do (`--json`, `--verbose`) |
|
|
117
|
+
| `excalideck serve deck.excalidraw` | present it at `http://127.0.0.1:5190` (reloads on change; `-o` opens a browser) |
|
|
118
|
+
| `excalideck render deck.excalidraw` | PNG per slide + `sheet.png` with all of them * |
|
|
119
|
+
| `excalideck record deck.excalidraw` | a `.webm` of the deck playing through * |
|
|
120
|
+
| `excalideck doctor` | can it run here? One line per check, a fix under each failure (`--json`) |
|
|
121
|
+
| `excalideck busy` | is the one running here busy? For scripts (`--json`) |
|
|
122
|
+
|
|
123
|
+
`excalideck` on its own serves the one deck in the folder, or the bundled example if there isn't one, so
|
|
124
|
+
`npx excalideck` shows you what this does. `excalideck <command> --help` explains one command.
|
|
125
|
+
|
|
126
|
+
\* needs Playwright: `npm i -D playwright && npx playwright install chromium` (a global install works too).
|
|
127
|
+
Everything else has no dependencies. Requires Node 20.6+.
|
|
128
|
+
|
|
129
|
+
It follows [Ed's CLI contract 1.0](https://github.com/edspencer/cli-contract): the same commands, flags, exit
|
|
130
|
+
codes and output as his other local tools, checked in CI by `npx cli-conformance`. `AGENTS.md` lists the parts
|
|
131
|
+
that don't apply (there's no `service`, as a deck presenter is started for a talk and stopped after it, and no
|
|
132
|
+
`update` yet: run `npm install -g excalideck@latest`).
|
|
133
|
+
|
|
134
|
+
**Player keys:** → / Space / PageDown next (clickers work) · ← back · 1–9 jump · **O** overview of the whole
|
|
135
|
+
board · **R** replay a transition · **T** / **A** try a different transition / appear style live · **S** slow
|
|
136
|
+
motion · **L** load a file · **F** full screen.
|
|
137
|
+
|
|
138
|
+
## How it works
|
|
139
|
+
|
|
140
|
+
The player reads the Excalidraw JSON, turns each frame into a slide, and gives every element a key: its label,
|
|
141
|
+
or for arrows, the labels at either end. Between two slides it pairs elements by key, then builds a timeline:
|
|
142
|
+
exits fade first, matched shapes move, and new ones arrive left to right, with arrows waiting for their
|
|
143
|
+
boxes. `zoom` finds the pair whose size changes most and applies the same camera move to everything else.
|
|
144
|
+
|
|
145
|
+
Each animation frame is redrawn with [rough.js](https://github.com/rough-stuff/rough), the library
|
|
146
|
+
Excalidraw itself draws with, using each element's saved random seed. That's why a box keeps its exact
|
|
147
|
+
hand-drawn wobble while it moves. Arrow ends remember where on their shape's outline they attach, so they
|
|
148
|
+
stay glued during morphs. The matching code is shared with `excalideck check`, so the report tells you
|
|
149
|
+
exactly what the player will do.
|
|
150
|
+
|
|
151
|
+
## Limits
|
|
152
|
+
|
|
153
|
+
- It re-implements Excalidraw's rendering rather than embedding Excalidraw. Rectangles, ellipses, diamonds,
|
|
154
|
+
arrows, text, images and freehand all render, but elbow arrows, rounded diamonds and some arrowhead
|
|
155
|
+
styles are approximate. The bundled font covers Latin text.
|
|
156
|
+
- A label that wraps differently on two slides cross-fades instead of morphing.
|
|
157
|
+
- Embeds (iframes, YouTube) aren't shown.
|
|
158
|
+
|
|
159
|
+
## Credits
|
|
160
|
+
|
|
161
|
+
Not affiliated with Excalidraw, but built on its work: the Excalifont and Virgil fonts
|
|
162
|
+
([OFL](player/THIRD_PARTY.md)) and the file format. Drawing by [rough.js](https://github.com/rough-stuff/rough) (MIT).
|
|
163
|
+
|
|
164
|
+
MIT © Ed Spencer
|
package/bin/excalideck
ADDED
package/cli/doctor.mjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// `excalideck doctor` (CLI contract SPEC §1): can it run here, and what to do about anything that can't.
|
|
2
|
+
// The service checks the spec lists (unit, running-version, port, linger) belong to a tool with a service;
|
|
3
|
+
// excalideck has none — see AGENTS.md.
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { accessSync, constants, existsSync } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { EXIT } from "../src/contract/exit-codes.js";
|
|
9
|
+
import { detectInstall, describeInstall } from "../src/contract/install-method.js";
|
|
10
|
+
import { satisfiesEngines } from "../src/contract/semver.js";
|
|
11
|
+
import { readLiveRuntimeFile } from "../src/contract/runtime-file.js";
|
|
12
|
+
import { ENV_PREFIX, home, NAME, PACKAGE_NAME, PKG, ROOT, VERSION } from "./paths.mjs";
|
|
13
|
+
|
|
14
|
+
export const DOCTOR_USAGE = `Usage: excalideck doctor [--json] [--offline]
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const DOCTOR_HELP = `excalideck doctor: check that excalideck can run here, with a fix for each problem.
|
|
18
|
+
|
|
19
|
+
${DOCTOR_USAGE}
|
|
20
|
+
--json one JSON document on stdout
|
|
21
|
+
--offline don't look anything up over the network
|
|
22
|
+
|
|
23
|
+
It exits 1 if any check fails. Warnings don't change the exit code.
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
const MARK = { pass: "✓", warn: "!", fail: "✗", skip: "·" };
|
|
27
|
+
|
|
28
|
+
export function parseDoctorArgs(args, UsageError) {
|
|
29
|
+
const opts = { json: false, offline: false };
|
|
30
|
+
for (const a of args) {
|
|
31
|
+
if (a === "-h" || a === "--help") return "help";
|
|
32
|
+
else if (a === "--json") opts.json = true;
|
|
33
|
+
else if (a === "--offline") opts.offline = true;
|
|
34
|
+
else if (a.startsWith("-")) throw new UsageError(`unknown option ${a}`);
|
|
35
|
+
else throw new UsageError(`\`doctor\` takes no argument (got ${a})`);
|
|
36
|
+
}
|
|
37
|
+
return opts;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** True if `dir` is writable; "creatable" if it doesn't exist but its nearest existing parent is; else why not. */
|
|
41
|
+
function writableOrCreatable(dir) {
|
|
42
|
+
let probe = dir;
|
|
43
|
+
while (!existsSync(probe)) {
|
|
44
|
+
const parent = dirname(probe);
|
|
45
|
+
if (parent === probe) return "no part of it exists";
|
|
46
|
+
probe = parent;
|
|
47
|
+
}
|
|
48
|
+
try { accessSync(probe, constants.W_OK); return probe === dir ? true : "creatable"; }
|
|
49
|
+
catch (err) { return `${probe} isn't writable (${err.code})`; }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function npmGlobalRoot() {
|
|
53
|
+
try { return execFileSync("npm", ["root", "-g"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim() || undefined; }
|
|
54
|
+
catch { return undefined; }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The same places `render` and `record` look (cli/media.mjs): the project, excalideck itself, a global install. */
|
|
58
|
+
function hasPlaywright() {
|
|
59
|
+
const g = npmGlobalRoot();
|
|
60
|
+
const from = [process.cwd(), ROOT, ...(g ? [join(g, "x"), join(g, "@playwright", "mcp", "x")] : [])];
|
|
61
|
+
for (const dir of from) {
|
|
62
|
+
for (const name of ["playwright", "playwright-core"]) {
|
|
63
|
+
try { createRequire(join(dir, "x.js")).resolve(name); return name; } catch { /* keep looking */ }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function diagnose({ entry = process.argv[1], offline = false } = {}) {
|
|
70
|
+
const checks = [];
|
|
71
|
+
const add = (id, status, message, fix) => checks.push({ id, status, message, ...(fix ? { fix } : {}) });
|
|
72
|
+
|
|
73
|
+
// 1. Does this Node satisfy our engines?
|
|
74
|
+
const verdict = satisfiesEngines(process.version, PKG.engines);
|
|
75
|
+
if (verdict.ok === false) add("node-engines", "fail", `Node ${process.version} doesn't satisfy engines.node ${verdict.range}`, `install Node ${verdict.range} (nvm install 22, say), then run excalideck again`);
|
|
76
|
+
else if (verdict.ok === undefined) add("node-engines", "warn", `Node ${process.version}; engines.node is ${verdict.range}, which couldn't be read`);
|
|
77
|
+
else add("node-engines", "pass", `Node ${process.version} satisfies engines.node ${verdict.range ?? "(unset)"}`);
|
|
78
|
+
|
|
79
|
+
// 2. How was it installed? (SPEC §6.)
|
|
80
|
+
const install = detectInstall({ entry, packageName: PACKAGE_NAME, envPrefix: ENV_PREFIX, env: process.env, npmGlobalRoot });
|
|
81
|
+
add("install-method", "pass", `Installed ${describeInstall(install)}${install.packageRoot ? ` (${install.packageRoot})` : ""}`);
|
|
82
|
+
|
|
83
|
+
// 3. The player's own files, which `serve` and `render` need.
|
|
84
|
+
const missing = ["player/index.html", "player/player.js", "player/vendor/rough.js", "player/fonts/Excalifont-Latin.woff2", "src/scene.js"]
|
|
85
|
+
.filter((f) => !existsSync(join(ROOT, f)));
|
|
86
|
+
if (missing.length) add("player-assets", "fail", `the player is incomplete: ${missing.join(", ")} missing`, "reinstall excalideck, or run `git status` in the checkout");
|
|
87
|
+
else add("player-assets", "pass", "the player and its fonts are present");
|
|
88
|
+
|
|
89
|
+
// 4. The data home, which `serve` writes runtime.json into.
|
|
90
|
+
const dataHome = home();
|
|
91
|
+
const w = writableOrCreatable(dataHome);
|
|
92
|
+
if (w === true) add("data-home", "pass", `${dataHome} is writable`);
|
|
93
|
+
else if (w === "creatable") add("data-home", "pass", `${dataHome} will be created when it's first needed`);
|
|
94
|
+
else add("data-home", "fail", `${dataHome} can't be written: ${w}`, `make it writable (chown or chmod), or set EXCALIDECK_HOME to somewhere that is`);
|
|
95
|
+
|
|
96
|
+
// 5. Playwright, for `render` and `record` only.
|
|
97
|
+
const pw = hasPlaywright();
|
|
98
|
+
if (pw) add("playwright", "pass", `${pw} is available, so \`render\` and \`record\` work`);
|
|
99
|
+
else add("playwright", "warn", "Playwright isn't installed, so `render` and `record` won't run (everything else does)");
|
|
100
|
+
|
|
101
|
+
// 6. Is one running here?
|
|
102
|
+
const live = readLiveRuntimeFile(dataHome);
|
|
103
|
+
if (live) add("running", "pass", `excalideck ${live.version} is serving at ${live.url} (pid ${live.pid})`);
|
|
104
|
+
else add("running", "pass", "nothing is serving here at the moment");
|
|
105
|
+
|
|
106
|
+
// 7. SPEC §1 asks doctor whether a newer version exists. excalideck has no `update` yet, so it doesn't ask.
|
|
107
|
+
add("update", "skip", offline ? "update check skipped (--offline)" : "no update check: excalideck has no `update` command yet (AGENTS.md)");
|
|
108
|
+
|
|
109
|
+
return checks;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const doctorCode = (checks) => (checks.some((c) => c.status === "fail") ? EXIT.FAILED : EXIT.OK);
|
|
113
|
+
|
|
114
|
+
export function renderChecks(checks, color) {
|
|
115
|
+
const tint = { pass: color.green, warn: color.yellow, fail: color.red, skip: color.dim };
|
|
116
|
+
return `${checks.map((c) =>
|
|
117
|
+
`${tint[c.status](MARK[c.status])} ${c.message}${c.fix && (c.status === "fail" || c.status === "warn") ? `\n fix: ${c.fix}` : ""}`
|
|
118
|
+
).join("\n")}\n`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** `excalideck doctor [--json] [--offline]`. Returns the exit code. */
|
|
122
|
+
export function runDoctor(opts, out) {
|
|
123
|
+
const checks = diagnose({ offline: opts.offline });
|
|
124
|
+
const code = doctorCode(checks);
|
|
125
|
+
if (opts.json) out.result({ ok: code === EXIT.OK, version: VERSION, checks });
|
|
126
|
+
else process.stdout.write(renderChecks(checks, out.color));
|
|
127
|
+
return code;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { NAME };
|