Skip to content

feat: shared @spoolid/core package; refactor web + desktop onto it#28

Open
mateusdemboski wants to merge 1 commit into
mainfrom
feat/issue-18-core-package
Open

feat: shared @spoolid/core package; refactor web + desktop onto it#28
mateusdemboski wants to merge 1 commit into
mainfrom
feat/issue-18-core-package

Conversation

@mateusdemboski

Copy link
Copy Markdown
Collaborator

Summary

PR3 of #18 — the deduplication payoff. Web and desktop now share one core package.

@spoolid/core (spec/ts) — root pnpm workspace member, imported by both frontends, zero runtime deps, exported as TS source (Vite inlines it; web pages stay single-file self-contained, ~5 KB gz total):

  • generated/ — wire types from spec/v2/schemas via json2ts (git-ignored, pnpm generate)
  • db.tsparseMaterialDb (single owner of result.list[].base + meterialType misspelling); kills the "mirrors the web client" copy
  • read.ts / status.ts — shared read-prefill + write-status interpretation (both pollStatus loops now one function)
  • compat.ts — protocol-first gate with major.minor fallback; fixes the dev-build skip that main.ts documented but never implemented (minorOf("0.0.0-dev") parsed as "0.0")
  • color.ts / ota.ts — hex normalization, swatch names (desktop's re-hardcoded 15-hex map deleted), OTA filename regex
  • tokens.css — one palette, token names documented in PROTOCOL.md. Web UI visibly changes: adopts the desktop green theme (was blue)
  • vitest: 14 tests incl. parsing the real material_database.json

Client refactors: desktop Reply is now a discriminated union (ok: true | ErrorReply) instead of Record<string, any>; applyRead/pollStatus/checkCompat/cmpVer/COLOR_NAMES deleted from main.ts; web app.ts/config.ts are DOM glue over core.

Workspace: root pnpm-workspace.yaml (web, desktop/frontend, spec/ts), one lockfile, nested workspace files removed. wails build -clean in CI/release (spec/ts changes don't dirty the frontend hash cache). build_web.py installs the workspace root.

Hardware verification: flashed v2 firmware; captured v2 fixtures (spec/status/config/read-error) from the live device; serial getspec verified byte-identical to HTTP /api/spec on hardware — the unification is real on the wire.

Verification

  • pnpm --dir spec/ts test → 14/14; validate.mjs green (v1+v2+generated fixtures)
  • pnpm --dir web build → 5 fixed-name self-contained files; tools/build_web.py → 5 .gz, ~5 KB
  • wails build -clean → SUCCESS; eslint clean; pio test -e native still green
  • Device smoke over both transports post-flash

Note: read.reply/ok.json + dump.reply/ok.json v2 fixtures are still hand-authored (need a tag on the reader to capture; shapes already machine-proven by the contract test in CI).

Closes #18.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SBnenzHAV3VVAF8b8hpwkT

spec/ts becomes the shared client core: TS wire types generated from
spec/v2 schemas (json2ts, git-ignored), deduplicated pure logic
(material-DB parsing incl. the meterialType quirk, read-prefill, write
status interpretation, color normalization, protocol/minor compat gate,
OTA target detection), design tokens (tokens.css - single palette, both
UIs; web adopts the desktop theme), and vitest coverage.

Both frontends now import @spoolid/core via a root pnpm workspace (one
lockfile; nested workspace files removed). The desktop serial layer
types replies as a discriminated union (ok: true | ErrorReply) instead
of Record<string, any>; the compat gate is shared and protocol-aware,
fixing the documented-but-unimplemented dev-build skip. v2 fixtures for
spec/status/config/read-error re-captured from a live v2 device; serial
getspec verified byte-identical to HTTP /api/spec on hardware.

CI: wails build -clean (spec/ts changes don't dirty the frontend hash
cache); build_web.py installs the workspace root.

Refs #18

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SBnenzHAV3VVAF8b8hpwkT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared core spec: single source of logic (read/write, material, tag format)

1 participant