easel-canvas 0.4.0 → 0.6.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/README.md +49 -11
- package/bin/mcp.mjs +2 -2
- package/bin/server.mjs +49 -15
- package/dist/assets/index-DE0ohrot.js +75 -0
- package/dist/assets/index-yigh_b3W.css +1 -0
- package/dist/favicon.svg +1 -0
- package/dist/index.html +3 -2
- package/package.json +3 -2
- package/server/args.mjs +4 -2
- package/server/chat.mjs +2 -0
- package/server/export.mjs +10 -3
- package/server/index.mjs +64 -5
- package/server/live/dispatch.mjs +168 -0
- package/server/live/inventory.mjs +101 -0
- package/server/live/live.mjs +366 -0
- package/server/live/proto.mjs +101 -0
- package/server/live/routes.mjs +49 -0
- package/server/requests.mjs +2 -0
- package/server/routes.mjs +17 -3
- package/server/selfupdate.mjs +98 -0
- package/server/up.mjs +1 -1
- package/server/update.mjs +80 -18
- package/dist/assets/index-DuziykA0.css +0 -1
- package/dist/assets/index-o294phw7.js +0 -74
- package/dist/viewer/viewer.css +0 -1
- package/dist/viewer/viewer.js +0 -56
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<h1><picture><source media="(prefers-color-scheme: dark)" srcset="brand/wordmark-dark.svg"><img src="brand/wordmark.svg" alt="Easel" width="152" height="47"></picture></h1>
|
|
4
4
|
|
|
5
5
|
**A design canvas where your coding agents and you work on the same real HTML.**
|
|
6
6
|
|
|
@@ -31,10 +31,10 @@ That copies the demo to `./easel-demo` and opens it at http://localhost:4317: In
|
|
|
31
31
|
Already have HTML screens? Run it in your project:
|
|
32
32
|
|
|
33
33
|
```bash
|
|
34
|
-
npx easel-canvas # opens ./docs/design (or the current folder if it has screens/)
|
|
35
|
-
npx easel-canvas --init # starts a new ./docs/design with one screen
|
|
36
|
-
npx easel-canvas --dir ./designs # any folder of screens/*.html
|
|
37
|
-
npx easel-canvas up # the same in the background: prints the URL, reuses a canvas already running here
|
|
34
|
+
npx easel-canvas@latest # opens ./docs/design (or the current folder if it has screens/)
|
|
35
|
+
npx easel-canvas@latest --init # starts a new ./docs/design with one screen
|
|
36
|
+
npx easel-canvas@latest --dir ./designs # any folder of screens/*.html
|
|
37
|
+
npx easel-canvas@latest up # the same in the background: prints the URL, reuses a canvas already running here
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Install into your agent
|
|
@@ -43,13 +43,13 @@ One line gives your agent the Easel tools and a skill that knows the canvas: whe
|
|
|
43
43
|
|
|
44
44
|
| Agent | Install | What you get |
|
|
45
45
|
| --- | --- | --- |
|
|
46
|
-
| **Claude Code** | `claude plugin marketplace add nemodleo/easel --sparse .claude-plugin plugin && claude plugin install easel@easel` | MCP tools, the `easel` skill, `/easel:open
|
|
46
|
+
| **Claude Code** | `claude plugin marketplace add nemodleo/easel --sparse .claude-plugin plugin && claude plugin install easel@easel` | MCP tools, the `easel` skill, `/easel:open`, `/easel:variants`, and a hook that [wakes the session](#claude-code-wakes-up-for-a-request) for canvas requests |
|
|
47
47
|
| **Codex** | `codex plugin marketplace add nemodleo/easel --sparse .agents/plugins --sparse plugin && codex plugin add easel@easel` | MCP tools and the `easel` skill |
|
|
48
48
|
| **Cursor** | `npx skills add nemodleo/easel --skill easel -a cursor` | The `easel` skill; add the tools with `npx easel-canvas connect` |
|
|
49
49
|
|
|
50
50
|
`--sparse` checks out only the plugin's folders instead of the whole repository with its screenshots, so the install stays fast on a slow connection.
|
|
51
51
|
|
|
52
|
-
Then, in your project, ask for what you want: *"open the design canvas"*, *"make three variants of the sign-up screen side by side"*, *"fix what I selected"*. In Claude Code, `/easel:open` starts the canvas for the project (or shows the one already running) and `/easel:variants signup.html 4` lays out four alternatives in a row below the original. The agent starts the canvas with `npx easel-canvas up`, which prints the URL and never starts a second one for the same folder.
|
|
52
|
+
Then, in your project, ask for what you want: *"open the design canvas"*, *"make three variants of the sign-up screen side by side"*, *"fix what I selected"*. In Claude Code, `/easel:open` starts the canvas for the project (or shows the one already running) and `/easel:variants signup.html 4` lays out four alternatives in a row below the original. The agent starts the canvas with `npx -y easel-canvas@latest up`, which prints the URL and never starts a second one for the same folder.
|
|
53
53
|
|
|
54
54
|
## Why Easel
|
|
55
55
|
|
|
@@ -104,7 +104,7 @@ Then, in your project, ask for what you want: *"open the design canvas"*, *"make
|
|
|
104
104
|
|
|
105
105
|
## Connect your AI agent
|
|
106
106
|
|
|
107
|
-
Keep the canvas running (`npx easel-canvas`). Agents write HTML files directly, and what they change shows up in the canvas's undo history (one step per in-app AI request, or per burst of edits from an outside agent); the MCP server lets them **see** (`list_boards`, `read_board`, `screenshot`, `list_errors`), **know what you mean** (`get_selection` with the selected element, visible boards and the current page), **talk** (comments and replies) and **arrange** (`place_board`, `create_board`, notes, pages, `check_tokens`, `save_snapshot`). When several agents share a canvas, `claim_board` (before editing a file with their own tools) or `write_board` (a whole board through Easel) keeps one writer per board: a second agent on a busy board is given a fork next to it and told which file it is on.
|
|
107
|
+
Keep the canvas running (`npx easel-canvas@latest`). Agents write HTML files directly, and what they change shows up in the canvas's undo history (one step per in-app AI request, or per burst of edits from an outside agent); the MCP server lets them **see** (`list_boards`, `read_board`, `screenshot`, `list_errors`), **know what you mean** (`get_selection` with the selected element, visible boards and the current page), **talk** (comments and replies) and **arrange** (`place_board`, `create_board`, notes, pages, `check_tokens`, `save_snapshot`). When several agents share a canvas, `claim_board` (before editing a file with their own tools) or `write_board` (a whole board through Easel) keeps one writer per board: a second agent on a busy board is given a fork next to it and told which file it is on.
|
|
108
108
|
|
|
109
109
|
Then, in your project folder (not needed for an agent that has the [plugin](#install-into-your-agent), which brings the same server):
|
|
110
110
|
|
|
@@ -154,12 +154,24 @@ New files with `<meta name="board-size" content="390x844">` are placed on the ca
|
|
|
154
154
|
|
|
155
155
|
When you already work with an agent next to the canvas (Claude desktop's Browser pane beside a Claude Code session, say), Easel does not need to start a second agent of its own. In the AI tab (or the **⋯** menu) set **AI requests go to** to **The agent you're talking to**; it is remembered for the project (`.easel/requests.json`, not committed).
|
|
156
156
|
|
|
157
|
-
From then on **Ask AI** on an element, **Send to AI** on a comment and **Ask AI to fix** (token check, accessibility, errors) leave a request on the canvas instead: a comment marked **For AI**, written in a small composer where the element toolbar sits. The pin gets an AI flag, the board says "1 waiting", and the AI button shows the count. Easel cannot type into your agent's chat
|
|
157
|
+
From then on **Ask AI** on an element, **Send to AI** on a comment and **Ask AI to fix** (token check, accessibility, errors) leave a request on the canvas instead: a comment marked **For AI**, written in a small composer where the element toolbar sits. The pin gets an AI flag, the board says "1 waiting", and the AI button shows the count. Easel cannot type into your agent's chat. With the Claude Code plugin the session [wakes up by itself](#claude-code-wakes-up-for-a-request); otherwise say there (the list shows this line once, with Copy, while a request waits):
|
|
158
158
|
|
|
159
159
|
> handle the Easel requests
|
|
160
160
|
|
|
161
161
|
(or `Easel 요청 처리해 줘`, or run `/easel:requests` with the plugin). The agent calls `list_requests`, `take_request` (one agent per request; the request says "Claude Code working" and the board "is editing…") and `finish_request`: its one-line reply lands under the comment, the comment is resolved, the changed board is one click away, and the board's activity tag has **Undo**. A request row is a comment with one mark and one line. A waiting request can be cancelled (it stays as a normal comment) or, behind its **⋯**, sent to **Easel chat** instead; a taken one cannot be cancelled, only undone afterwards. In a pane 1200 px wide or less the AI tab lists the requests first and shows the setting as one line ("Requests go to: your agent"). With two or more agents connected you can address one of them. View-only exports show For AI comments as ordinary comments.
|
|
162
162
|
|
|
163
|
+
#### Claude Code wakes up for a request
|
|
164
|
+
|
|
165
|
+
The Claude Code plugin (not the MCP server alone, and not Codex, Cursor or Gemini) adds a hook that ends the "now go tell your agent" step: while the session sits idle, a request you leave on the canvas wakes it within a few seconds, and it handles the request as `/easel:requests` does. You see the session start working on its own.
|
|
166
|
+
|
|
167
|
+
- **How.** `plugin/hooks/claude-code.json` (declared in the Claude Code manifest `plugin/.claude-plugin/plugin.json` only, and not at the default `hooks/hooks.json`, so other agents' plugin loaders, such as Codex's, do not pick it up) runs `plugin/hooks/wake.mjs` (Node, no dependencies) on `SessionStart` and again after every turn (`Stop`), as an `asyncRewake` hook: it waits in the background and exits with code 2 to wake the session. It finds the running canvas for the session's folder in the registry (`~/.easel/servers`), the same way the MCP server does, but only a canvas whose folder contains the session's folder or is the one canvas inside it; it never starts a canvas, and when none is running it checks again every 5 seconds. Every 2 seconds it reads the waiting requests (`GET /api/requests`, read only; it does not count as an agent looking).
|
|
168
|
+
- **What wakes it.** Only waiting requests meant for Claude Code (for any agent, or addressed to Claude Code), and only while **AI requests go to** is **The agent you're talking to**. Easel's own chat runs and requests for another agent never wake it.
|
|
169
|
+
- **Once per request, again if the wake was lost.** A request is announced as soon as it waits (`~/.easel/wake/announced/`). A wake that lands while the session's turn is still running can be dropped, so after the session's next turn ends the new watcher announces the request again if no agent has listed it yet (the request has no `seenAt`), at most 3 more times and no sooner than 20 seconds after the last announcement. A request an agent has listed but not taken is not announced again. It starts over when it goes back to waiting (sent again after a failure, or the agent that took it left).
|
|
170
|
+
- **Several sessions on one project.** Each session has its own watcher (one per session; a second one exits at once), but they share the announcements, so only one watcher wins each announcement and wakes its session; a watcher that was already running when a request was announced never announces it again. If two sessions do act on the same request, `take_request` lets only one take it.
|
|
171
|
+
- **What Claude reads.** One line with the number of new requests and what to do. The request text is never in it; Claude reads it with `list_requests`.
|
|
172
|
+
- **Opt out.** Set `EASEL_NO_WAKE=1` in the environment Claude Code starts with, or keep **AI requests go to** on **Easel chat**.
|
|
173
|
+
- **Limits.** The hook runs for at most a day (`timeout: 86400`); a session idle for longer than that is not woken until its next turn ends, which starts a new watcher. A request made while the session is busy is announced during that turn; if that wake is lost, it is announced again once the turn has ended and at least 20 seconds have passed since the first announcement. With several sessions open, the repeat can wake another session started or re-armed since then, not necessarily the one that lost it. macOS and Linux; on Windows the hook does nothing. It needs a Claude Code version with `asyncRewake` hooks. Set `EASEL_WAKE_LOG=<file>` to log what the watcher does.
|
|
174
|
+
|
|
163
175
|
Each board frame also carries `data-easel-file` (and `data-easel-path` while you have something selected on it), so when your host's own element picker grabs part of the canvas, the agent can turn it into a file and element with `resolve_pick`.
|
|
164
176
|
|
|
165
177
|
## Share a view-only copy
|
|
@@ -183,9 +195,35 @@ To show the copy inside another page, frame its `index.html` with `?embed`: the
|
|
|
183
195
|
|
|
184
196
|
Exporting again replaces what the previous export of the same kind wrote there (a small `.easel-export.json` lists it) and leaves anything else in the folder alone; a non-empty folder Easel did not create is never cleared. Dot folders (`.easel/`, `.thumbs/`…) and files outside the design folder are never copied. A single file inlines the screens' images, fonts, CSS and scripts but not HTML embedded with `<iframe>`; the export lists what it skipped.
|
|
185
197
|
|
|
198
|
+
## Live share
|
|
199
|
+
|
|
200
|
+
**Share › Live share › Start** gives you a link that lets other people watch your canvas with you while Easel is open: they see your boards as they change, everyone's cursor and name, and the comments. Pick what the link opens as: **View**, or **Comment** (guests can add comments and replies, marked *Guest* on your canvas). Editing is not part of this version. The share pill in the top-right card shows who is there; **Stop** ends it for everyone, **New link** replaces the link for that role and closes the guests who came by the old one, and closing Easel ends it too. Links do not survive a restart, and there are no accounts.
|
|
201
|
+
|
|
202
|
+
How it is kept safe, in plain words:
|
|
203
|
+
|
|
204
|
+
- **Your computer stays the source.** Easel opens one outgoing connection to a relay; nothing on your machine starts listening to the internet. Guests' requests are answered inside Easel by a short allow-list written for guests (the board list, comments without your AI requests, and the files your boards load). Anything else — AI runs, edits, history, settings, your file paths — is refused before any of Easel's own routes run. A test fails if a new route is added without deciding whether guests may have it.
|
|
205
|
+
- **The relay cannot read anything.** The key is in the link's `#` part, which browsers never send to a server. Every message is encrypted end to end (AES-GCM, a key per link role), so the relay only passes along bytes it cannot open. Whoever has the link has the key: share it like you would share the screen.
|
|
206
|
+
- **Guests cannot pretend.** The role comes from which link's key opens a guest's messages; the name on a comment is the one the guest typed (shown as *Guest*), and a guest comment is never a request for your AI agent.
|
|
207
|
+
- **Boards run apart from the key.** The link page that holds the key shows the canvas in a frame on a second site (the board host), so a board's own scripts cannot reach the key or the connection. Boards are your own files and are treated as such.
|
|
208
|
+
- **Ending clears; dropping keeps, for a while.** **Stop** or **New link** clears what those guests were looking at. A guest who was away at that moment (asleep, offline) is told it ended when they come back: the relay remembers that a room was ended, by its id and the time only, for 24 hours. A dropped connection (your laptop sleeps, Easel quits without Stop, the network or the relay goes) leaves guests the last state they saw, read-only and marked *Disconnected*; after 10 minutes without you the guest page clears it too and says so, while it keeps trying to reconnect and picks up again when you are back. What a guest received stays only in that browser tab: Easel's guest page writes nothing to disk (no Cache Storage, no IndexedDB, answers marked `no-store`).
|
|
209
|
+
- **The name guests see** is your comment author name (your git name until you change it). **Share › Live share** shows it and changes it in place; it is saved in this browser, not in the design folder.
|
|
210
|
+
- **Limits.** Up to 20 guests per room, a request rate and queue per guest (more get "slow down"), 1 MB per message, 32 MB per file, and a guest whose connection cannot keep up is dropped rather than buffered.
|
|
211
|
+
|
|
212
|
+
Easel connects to `wss://easel.d-t-it.com/live/ws` unless you pass `--relay <url>` (or set `EASEL_RELAY`). If the relay cannot be reached, the popover says live share is not available and nothing else changes. The relay is open source in [`relay/`](relay/): a small Node server (`node relay/node.mjs`) and a Cloudflare Worker with a Durable Object (`relay/worker.mjs`) speaking the same protocol, so you can run your own; [docs/live-share-deploy.md](docs/live-share-deploy.md) has the steps.
|
|
213
|
+
|
|
214
|
+
Try it on one machine (two origins on loopback ports, the Node relay in between):
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npm run build # also builds dist/live (the link page and the board host)
|
|
218
|
+
node relay/node.mjs # relay :4480, link page :4481, board host :4482
|
|
219
|
+
npx easel-canvas --relay ws://127.0.0.1:4480/live/ws # or: node bin/server.mjs --relay ws://127.0.0.1:4480/live/ws
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Then **Share › Live share › Start**, copy the link and open it in another browser profile.
|
|
223
|
+
|
|
186
224
|
## Pin it in your project
|
|
187
225
|
|
|
188
|
-
`npx easel-canvas` is all most projects need. To pin an exact version for your team, add it as a dev dependency (`npm i -D easel-canvas`, then `"design": "easel-canvas"` in your scripts) or as a git submodule. With your designs in `<project>/docs/design/screens/`:
|
|
226
|
+
`npx easel-canvas@latest` is all most projects need. To pin an exact version for your team, add it as a dev dependency (`npm i -D easel-canvas`, then `"design": "easel-canvas"` in your scripts) or as a git submodule. With your designs in `<project>/docs/design/screens/`:
|
|
189
227
|
|
|
190
228
|
```bash
|
|
191
229
|
git submodule add https://github.com/nemodleo/easel.git tools/easel
|
|
@@ -290,7 +328,7 @@ npm run verify:agents # before a release: install Easel into each agent CLI on
|
|
|
290
328
|
| `app/` | Canvas UI (Vite + React + TypeScript); all UI text lives in `app/src/strings.ts`, in English and Korean (the Korean object is typed against the English one, so a missing string is a type error) |
|
|
291
329
|
| `test/` | `node --test` unit tests and Playwright e2e tests |
|
|
292
330
|
| `tools/` | Repo maintenance scripts, not shipped: `mkcss.mjs` builds the design boards' stylesheet from the app's, `plugin-sync.mjs` keeps the plugin manifests at the package version, `verify-agents.mjs` checks real agent installs |
|
|
293
|
-
| `plugin/` | The agent plugin: MCP server entry, the `easel` skill, `/easel:open` and `/easel:
|
|
331
|
+
| `plugin/` | The agent plugin: MCP server entry, the `easel` skill, `/easel:open`, `/easel:variants` and `/easel:requests`, and the Claude Code wake hook (`hooks/`) |
|
|
294
332
|
|
|
295
333
|
Background reading: the original plan is in [PLAN.md](PLAN.md) and the work log is in [tasks.md](tasks.md).
|
|
296
334
|
|
package/bin/mcp.mjs
CHANGED
|
@@ -68,7 +68,7 @@ async function call(method, path, body) {
|
|
|
68
68
|
res = await send();
|
|
69
69
|
} catch (e2) {
|
|
70
70
|
if (e2.message?.startsWith("Several Easel canvases")) throw e2;
|
|
71
|
-
throw new Error(`Easel is not running for this project (tried http://localhost:${port}). Start it in the project with \`npx easel-canvas\` (add --dir <design folder> when the screens are not in ./docs/design or the current folder), then try again.`);
|
|
71
|
+
throw new Error(`Easel is not running for this project (tried http://localhost:${port}). Start it in the project with \`npx easel-canvas@latest\` (add --dir <design folder> when the screens are not in ./docs/design or the current folder), then try again.`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
const text = await res.text();
|
|
@@ -164,7 +164,7 @@ tool(
|
|
|
164
164
|
"get_selection",
|
|
165
165
|
{
|
|
166
166
|
description:
|
|
167
|
-
"What the user is looking at right now: selection (the element the user clicked on a board: file, path as element indexes from the children of <body>, tag, kind and label, text, source outerHTML up to 4KB, hash, computed styles), mode (canvas, edit = an element is selected, focus, play), page and pageName, visibleArtboards (boards visible on screen), selectedArtboards, dirty (pending saves), edits (recent edit history), erroredArtboards and firstError (boards with errors).
|
|
167
|
+
"What the user is looking at right now: selection (the element the user clicked on a board: file, path as element indexes from the children of <body>, tag, kind and label, text, source outerHTML up to 4KB, hash, computed styles), mode (canvas, edit = an element is selected, focus, play), page and pageName, visibleArtboards (boards visible on screen), selectedArtboards, dirty (pending saves), edits (recent edit history), erroredArtboards and firstError (boards with errors). Call it first whenever a message points at something without naming it ('fix this', 'make it bigger', 'this screen', 'the selected element', '이거 고쳐'), and work on what it returns.",
|
|
168
168
|
inputSchema: {},
|
|
169
169
|
},
|
|
170
170
|
async () => {
|
package/bin/server.mjs
CHANGED
|
@@ -19,18 +19,19 @@ if (args.help) {
|
|
|
19
19
|
console.log(`Easel ${pkg.version} — an HTML design canvas for AI agents
|
|
20
20
|
|
|
21
21
|
Usage
|
|
22
|
-
npx easel-canvas open ./docs/design (or the current folder if it has screens/)
|
|
23
|
-
npx easel-canvas --demo copy the demo project to ./easel-demo and open it
|
|
24
|
-
npx easel-canvas --init create ./docs/design with a starter screen, then open it
|
|
25
|
-
npx easel-canvas --dir <folder> open a specific design folder
|
|
26
|
-
npx easel-canvas up start the canvas in the background unless one runs for this project; print its URL
|
|
27
|
-
npx easel-canvas status
|
|
28
|
-
npx easel-canvas connect
|
|
29
|
-
npx easel-canvas export
|
|
22
|
+
npx easel-canvas@latest open ./docs/design (or the current folder if it has screens/)
|
|
23
|
+
npx easel-canvas@latest --demo copy the demo project to ./easel-demo and open it
|
|
24
|
+
npx easel-canvas@latest --init create ./docs/design with a starter screen, then open it
|
|
25
|
+
npx easel-canvas@latest --dir <folder> open a specific design folder
|
|
26
|
+
npx easel-canvas@latest up start the canvas in the background unless one runs for this project; print its URL
|
|
27
|
+
npx easel-canvas status print the URL of the canvas running for this project (exit 1 when there is none)
|
|
28
|
+
npx easel-canvas connect add the Easel MCP server to your agents' configs (run in the project)
|
|
29
|
+
npx easel-canvas export write a view-only copy of the canvas to ./easel-export (no canvas needed)
|
|
30
30
|
|
|
31
31
|
Options
|
|
32
32
|
--port <n> port to listen on (default 4317; when it is busy and --port is not given, the next free one)
|
|
33
33
|
--open open the canvas in your browser (--demo and --init do this; --no-open to skip)
|
|
34
|
+
--relay <url> live-share relay (default wss://easel.d-t-it.com/live/ws, or EASEL_RELAY; see README "Live share")
|
|
34
35
|
-h, --help show this help
|
|
35
36
|
-v, --version
|
|
36
37
|
|
|
@@ -64,7 +65,7 @@ if (args.command === "connect") {
|
|
|
64
65
|
try {
|
|
65
66
|
const lines = await connect({ project: args.dirGiven ? rootOf(args.dir) : process.cwd(), agents: args.agents, dryRun: args.dryRun });
|
|
66
67
|
console.log(lines.join("\n"));
|
|
67
|
-
if (!args.dryRun) console.log("\nStart the canvas with npx easel-canvas, then restart your agent so it loads the MCP server.");
|
|
68
|
+
if (!args.dryRun) console.log("\nStart the canvas with npx easel-canvas@latest, then restart your agent so it loads the MCP server.");
|
|
68
69
|
} catch (e) {
|
|
69
70
|
console.error(e.message);
|
|
70
71
|
process.exit(1);
|
|
@@ -132,25 +133,57 @@ if (!existsSync(dir)) {
|
|
|
132
133
|
console.error(`No design folder at ${dir}
|
|
133
134
|
|
|
134
135
|
Try one of:
|
|
135
|
-
npx easel-canvas --demo open the demo project
|
|
136
|
-
npx easel-canvas --init start a new design folder here (./docs/design)
|
|
137
|
-
npx easel-canvas --dir <folder> open an existing folder of screens/*.html`);
|
|
136
|
+
npx easel-canvas@latest --demo open the demo project
|
|
137
|
+
npx easel-canvas@latest --init start a new design folder here (./docs/design)
|
|
138
|
+
npx easel-canvas@latest --dir <folder> open an existing folder of screens/*.html`);
|
|
138
139
|
process.exit(1);
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
const { createServer } = await import("../server/index.mjs");
|
|
142
143
|
const { attach, closeBrowser, extraRoutes } = await import("../server/routes.mjs");
|
|
144
|
+
const { waitForNew } = await import("../server/selfupdate.mjs");
|
|
143
145
|
let app;
|
|
146
|
+
let child = null; // after a hand-over: the new server, which this process only waits on
|
|
147
|
+
const start = async (port, autoPort) => {
|
|
148
|
+
const a = await createServer({ dir, port, dev: !args.prod, extraRoutes, autoPort, register: true, updateCheck: true });
|
|
149
|
+
await attach(a, { relay: args.relay });
|
|
150
|
+
a.ctx.handover = handover;
|
|
151
|
+
return a;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* One-click update (server/selfupdate.mjs installed the new files at root): this server lets go of its port, the new one starts on the
|
|
155
|
+
* same port and folder, and this process stays as its parent (Ctrl+C and the terminal still reach it). If the new one has not answered
|
|
156
|
+
* in 30 s it is stopped and this one listens again, so there is always a canvas. Resolves to whether the new one took over.
|
|
157
|
+
*/
|
|
158
|
+
async function handover(root) {
|
|
159
|
+
const port = app.port;
|
|
160
|
+
await app.close();
|
|
161
|
+
const next = spawn(process.execPath, [path.join(root, "bin", "server.mjs"), "--dir", dir, "--port", String(port), "--no-open", ...(args.prod ? ["--prod"] : []), ...(args.relay ? ["--relay", args.relay] : [])], { stdio: "inherit", env: process.env, windowsHide: true });
|
|
162
|
+
let dead = false;
|
|
163
|
+
next.on("exit", () => (dead = true));
|
|
164
|
+
next.on("error", () => (dead = true));
|
|
165
|
+
if (await waitForNew({ port, pid: process.pid, alive: () => !dead })) {
|
|
166
|
+
child = next;
|
|
167
|
+
next.on("exit", (code, sig) => process.exit(code ?? (sig ? 1 : 0)));
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
next.kill("SIGTERM");
|
|
172
|
+
} catch {}
|
|
173
|
+
await new Promise((r) => (dead ? r() : next.once("exit", r), setTimeout(r, 3000)));
|
|
174
|
+
app = await start(port, false);
|
|
175
|
+
app.ctx.updateState = { phase: "failed", why: "restart" };
|
|
176
|
+
console.error(`The new Easel did not start on port ${port}; this one keeps running.`);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
144
179
|
try {
|
|
145
|
-
app = await
|
|
180
|
+
app = await start(args.port, !args.portGiven);
|
|
146
181
|
} catch (e) {
|
|
147
182
|
if (e.code !== "EADDRINUSE") throw e;
|
|
148
183
|
console.error(e.message);
|
|
149
184
|
process.exit(1);
|
|
150
185
|
}
|
|
151
|
-
await attach(app);
|
|
152
186
|
console.log(`Easel: ${app.url} (design folder ${dir})${app.port !== args.port ? ` port ${args.port} was busy` : ""}`);
|
|
153
|
-
app.update.then((u) => u && console.log(`Easel ${u.latest} is out (you have ${u.current}). Update: ${u.command}, then restart.`));
|
|
154
187
|
|
|
155
188
|
if (open && !args.noOpen) {
|
|
156
189
|
const [cmd, cmdArgs] = process.platform === "darwin" ? ["open", [app.url]] : process.platform === "win32" ? ["cmd", ["/c", "start", "", app.url]] : ["xdg-open", [app.url]];
|
|
@@ -160,6 +193,7 @@ if (open && !args.noOpen) {
|
|
|
160
193
|
process.on("exit", () => app.unregister());
|
|
161
194
|
for (const sig of ["SIGTERM", "SIGINT", "SIGHUP"])
|
|
162
195
|
process.on(sig, async () => {
|
|
196
|
+
if (child) return void child.kill(sig); // the new server ends, then this process with it
|
|
163
197
|
app.unregister();
|
|
164
198
|
await closeBrowser();
|
|
165
199
|
process.exit(0);
|