2026-07-21 14:03:07 +02:00
|
|
|
# codegen — schemas → C++ + TypeScript
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
Bun scripts that turn the JSON schemas under `schemas/` into generated code for both
|
|
|
|
|
targets. The per-file inventory lives in `MAP.md` (§ `codegen/`) — this README only
|
|
|
|
|
covers how to run it.
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
- `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`.
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
Both validate with ajv (Draft 2020-12), exit non-zero on failure, and are idempotent
|
|
|
|
|
(re-running with unchanged schemas is byte-identical).
|
2026-04-29 14:29:08 +02:00
|
|
|
|
|
|
|
|
## Run
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cd codegen
|
2026-07-21 14:03:07 +02:00
|
|
|
bun install
|
|
|
|
|
bun run generate.ts # mode schemas
|
|
|
|
|
bun run generate-midi-devices.ts # MIDI device templates
|
2026-04-29 14:29:08 +02:00
|
|
|
```
|
|
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
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.
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
## Golden test
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
`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:
|
2026-04-29 14:29:08 +02:00
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
bun run test
|
|
|
|
|
```
|
|
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
After an intentional emission change, refresh the goldens:
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
```bash
|
|
|
|
|
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/
|
2026-04-29 14:29:08 +02:00
|
|
|
```
|
|
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
## Adding a mode / device
|
2026-04-29 14:29:08 +02:00
|
|
|
|
2026-07-21 14:03:07 +02:00
|
|
|
Drop the new JSON into `schemas/modes/` (or `schemas/midi_devices/`), run the matching
|
|
|
|
|
generator, and commit the JSON plus the regenerated outputs together.
|