memlnaut-nisps/codegen
monkey-w1n5t0n 7ce4598a0b chore(schemas): retire the clobbering seed script; fix the direction-of-truth text
Phase 3 (L39, ST13, ST9, ST10).

- L39: deleted codegen/seed-midi-devices.ts. It regenerated — and therefore
  silently CLOBBERED — the hand-tuned device schemas it had originally created.
  Its purpose is served and git retains it. Confirmed nothing invokes it (the
  root package.json that once might have was deleted in Phase 1).
- ST13: moved the provenance artifact out of the repo root. AUDIT CORRECTION:
  the finding's proposed destination, schemas/midi_devices/synth-midi-cc.sources.json,
  would have BROKEN codegen and CI — generate-midi-devices.ts treats every *.json
  directly under that directory as a device template and ajv-validates it, and
  the sources file has no device_id/midi/params, so the generator would exit
  non-zero. It went to schemas/midi_devices/sources/ instead.
- ST9: schemas/schema.json's own description stated the direction of truth
  BACKWARDS. Rewritten: schemas are canonical, codegen emits C++ and TypeScript.
  (The audit cited params_notes.md; the real path is schemas/modes/params_notes.md.)
- ST10: codegen/README.md rewritten against current reality — it described
  retired playground paths and a phantom temp dir.

Descriptions are never emitted, so this is behaviour-inert; proven by
regenerating all four generated directories byte-identically.
2026-07-21 14:03:07 +02:00
..
tests refactor(codegen): codegen owns mode identity, per-mode schemas and net dims 2026-07-21 14:02:23 +02:00
.gitignore Add codegen tool: schemas -> C++ headers + TS modules 2026-04-29 15:29:08 +03:00
generate-midi-devices.ts refactor(codegen): codegen owns mode identity, per-mode schemas and net dims 2026-07-21 14:02:23 +02:00
generate.ts refactor(codegen): codegen owns mode identity, per-mode schemas and net dims 2026-07-21 14:02:23 +02:00
lib.ts refactor(codegen): codegen owns mode identity, per-mode schemas and net dims 2026-07-21 14:02:23 +02:00
package.json Add codegen tool: schemas -> C++ headers + TS modules 2026-04-29 15:29:08 +03:00
README.md chore(schemas): retire the clobbering seed script; fix the direction-of-truth text 2026-07-21 14:03:07 +02:00
tsconfig.json Add codegen tool: schemas -> C++ headers + TS modules 2026-04-29 15:29:08 +03:00

codegen — schemas → C++ + TypeScript

Bun scripts that turn the JSON schemas under schemas/ into generated code for both targets. The per-file inventory lives in MAP.mdcodegen/) — this README only covers how to run it.

  • generate.ts — validates schemas/modes/*.json against schemas/schema.json, emits nisps/modes/generated/<mode>_schema.hpp (+ schema_types.hpp) and manifold/src/modes/generated/<mode>_schema.ts (+ types.ts, index.ts).
  • generate-midi-devices.ts — validates schemas/midi_devices/*.json against schemas/midi_device.schema.json, emits nisps/midi/generated/midi_devices.hpp and manifold/src/midi-devices/generated/{types,devices,index}.ts.

Both validate with ajv (Draft 2020-12), exit non-zero on failure, and are idempotent (re-running with unchanged schemas is byte-identical).

Run

cd codegen
bun install
bun run generate.ts               # mode schemas
bun run generate-midi-devices.ts  # MIDI device templates

Schema or codegen changes ship with the regenerated C++ and TypeScript in the same commit — CI re-runs both generators and fails on any diff.

Golden test

tests/golden_test.ts re-runs generate.ts against the live output dirs, diffs paf_synth_schema.{hpp,ts} against the snapshots in tests/golden/, then re-runs to prove idempotency:

bun run test

After an intentional emission change, refresh the goldens:

bun run generate.ts
cp ../nisps/modes/generated/paf_synth_schema.hpp tests/golden/
cp ../manifold/src/modes/generated/paf_synth_schema.ts tests/golden/

Adding a mode / device

Drop the new JSON into schemas/modes/ (or schemas/midi_devices/), run the matching generator, and commit the JSON plus the regenerated outputs together.