|
| 1 | +# Code Generation Command |
| 2 | + |
| 3 | +The `codegen` command generates type-safe client SDKs from Go source code annotations. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```bash |
| 8 | +viiper codegen [flags] |
| 9 | +``` |
| 10 | + |
| 11 | +## Description |
| 12 | + |
| 13 | +Scans the VIIPER server codebase to extract: |
| 14 | +- API routes and response DTOs |
| 15 | +- Device wire formats from `viiper:wire` comment tags |
| 16 | +- Device constants (keycodes, modifiers, button masks) |
| 17 | + |
| 18 | +Then generates client SDKs for C, C#, and TypeScript with: |
| 19 | +- Management API clients |
| 20 | +- Device-agnostic stream wrappers |
| 21 | +- Per-device encode/decode functions |
| 22 | +- Typed constants and enums |
| 23 | + |
| 24 | +## Flags |
| 25 | + |
| 26 | +### `--output` |
| 27 | + |
| 28 | +Output directory for generated SDKs (relative to repository root). |
| 29 | + |
| 30 | +**Default:** `../clients` |
| 31 | +**Environment Variable:** `VIIPER_CODEGEN_OUTPUT` |
| 32 | + |
| 33 | +**Example:** |
| 34 | + |
| 35 | +```bash |
| 36 | +viiper codegen --output=../sdk-output |
| 37 | +``` |
| 38 | + |
| 39 | +### `--lang` |
| 40 | + |
| 41 | +Target language to generate. |
| 42 | + |
| 43 | +**Values:** `c`, `csharp`, `typescript`, `all` |
| 44 | +**Default:** `all` |
| 45 | +**Environment Variable:** `VIIPER_CODEGEN_LANG` |
| 46 | + |
| 47 | +**Examples:** |
| 48 | + |
| 49 | +```bash |
| 50 | +# Generate all SDKs |
| 51 | +viiper codegen --lang=all |
| 52 | + |
| 53 | +# Generate C SDK only |
| 54 | +viiper codegen --lang=c |
| 55 | + |
| 56 | +# Generate C# SDK only |
| 57 | +viiper codegen --lang=csharp |
| 58 | + |
| 59 | +# Generate TypeScript SDK only |
| 60 | +viiper codegen --lang=typescript |
| 61 | +``` |
| 62 | + |
| 63 | +## Output Structure |
| 64 | + |
| 65 | +Generated files are organized by language: |
| 66 | + |
| 67 | +``` |
| 68 | +clients/ |
| 69 | +├── c/ |
| 70 | +│ ├── include/viiper/ |
| 71 | +│ │ ├── viiper.h |
| 72 | +│ │ ├── viiper_keyboard.h |
| 73 | +│ │ ├── viiper_mouse.h |
| 74 | +│ │ └── viiper_xbox360.h |
| 75 | +│ ├── src/ |
| 76 | +│ │ ├── viiper.c |
| 77 | +│ │ ├── viiper_keyboard.c |
| 78 | +│ │ ├── viiper_mouse.c |
| 79 | +│ │ └── viiper_xbox360.c |
| 80 | +│ └── CMakeLists.txt |
| 81 | +├── csharp/ |
| 82 | +│ └── Viiper.Client/ |
| 83 | +│ └── (generated C# files) |
| 84 | +└── ts/ |
| 85 | + └── viiperclient/ |
| 86 | + └── (generated TypeScript files) |
| 87 | +``` |
| 88 | + |
| 89 | +## Examples |
| 90 | + |
| 91 | +### Generate All SDKs |
| 92 | + |
| 93 | +```bash |
| 94 | +cd viiper |
| 95 | +go run ./cmd/viiper codegen |
| 96 | +``` |
| 97 | + |
| 98 | +### Generate C SDK and Rebuild Examples |
| 99 | + |
| 100 | +```bash |
| 101 | +cd viiper |
| 102 | +go run ./cmd/viiper codegen --lang=c |
| 103 | +cd ../examples/c |
| 104 | +cmake --build build --config Release |
| 105 | +``` |
| 106 | + |
| 107 | +### CI/CD Integration |
| 108 | + |
| 109 | +```yaml |
| 110 | +- name: Generate Client SDKs |
| 111 | + run: | |
| 112 | + cd viiper |
| 113 | + go run ./cmd/viiper codegen --lang=all |
| 114 | +``` |
| 115 | +
|
| 116 | +## When to Regenerate |
| 117 | +
|
| 118 | +Run codegen when any of these change: |
| 119 | +
|
| 120 | +- `pkg/apitypes/*.go`: API response structures |
| 121 | +- `pkg/device/*/inputstate.go`: Wire format annotations |
| 122 | +- `pkg/device/*/const.go`: Exported constants |
| 123 | +- `internal/server/api/*.go`: Route registrations |
| 124 | +- Generator templates in `internal/codegen/generator/` |
| 125 | + |
| 126 | +## See Also |
| 127 | + |
| 128 | +- [Generator Documentation](../clients/generator.md): Detailed explanation of tagging system and code generation flow |
| 129 | +- [C SDK Documentation](../clients/c.md): C-specific usage and build instructions |
| 130 | +- [Configuration](configuration.md): Global configuration options |
0 commit comments