Skip to content

Latest commit

 

History

History
14 lines (10 loc) · 3.42 KB

adding-calculator.md

File metadata and controls

14 lines (10 loc) · 3.42 KB

Adding a calculator

  1. Agree and document domain, units, limits, rounding, undefined inputs and approximation tolerances first.
  2. Add packages/calculators/src/<stable-id>/metadata.json with stable id/slug, catalog translation keys, schema version and operation-to-field-name map. Add index.ts exporting an operation descriptor map, typed canonical input, generic calculate(input) entry, module-specific error/result/visual types and visual extension point. Add fixtures beside it. Do not add central unions or generator registrations.
  3. Add packages/content/src/<stable-id>/index.ts with structured lesson blocks, stable lowercase IDs, formula variables with units, authored examples and working message keys. Add packages/i18n/src/topics/<stable-id>.ts for lesson/UI operation/working/error messages. Only title/description/search metadata belongs in the light base i18n/src/en.ts. Related blocks must reference existing catalog IDs.
  4. Run bun run generate, which validates metadata/module files and emits catalog/schema and lazy engine/lesson/topic-message imports. Run bun run generate:web-topics to emit one static Astro route and literal-view island wrapper per catalog item; this also requires a DOM view.tsx and adapter.ts for every web topic. bun run build:web regenerates routes before the production build. Run bun run check:generated, bun run check:web-topics, bun run content-check, bun run test, bun run typecheck, and bun run lint. Content validation dynamically checks all generated lesson/message entries; test fixtures should cover multiple modules without adding fake product calculators.
  5. Add package-level runtime dependency declarations only when source imports cross package boundaries. Do not add a platform or central switch to register the topic.
  6. Verify result, working, visual data and its text/table alternative all consume the same result in actual interfaces. Record platform/offline evidence separately; a passing engine test is not interface or offline evidence.

For a platform runtime adapter, implement TopicAdapter<R, Code> in the topic-owned DOM runtime boundary: provide the generated calculator ID, input schema version, descriptors, a locale-aware parser returning canonical strings/incomplete/invalid, and a typed calculate function. Do not route topic-specific input through a shared decimal parser or normalize distinct results into a central union. The DOM view is discovered independently by Vite at packages/dom-ui/src/topics/<id>/view.tsx. A native view belongs at apps/mobile/src/topics/<id>/view.tsx; after it exists, run bun run generate:mobile-views and commit the generated index.generated.ts, never hand-edit that output. The explicit mobile check reports missing catalog views; unrelated web/desktop builds do not require them.

Catalog generation uses literal metadata and import maps because Astro route discovery needs build-time catalog data and Expo must not rely on Vite's import.meta.glob. Discovery must not eagerly import an engine or lesson. Web route generation uses the same catalog metadata to create per-slug static routes, with static topic view/adapter imports and lazy engine, lesson, and message imports.

A new calculator belongs to exactly one pack in packs/<pack-id>/pack.json via calculatorIds. Add the membership before running the generator. Engines cannot import another pack's topic; shared primitives belong in core runtime modules. See packs.md.