opencode/packages/cli-rs/script/gen/config.ts
Simon Klee 6b1df0cceb
feat(cli-rs): add the native CLI and TUI (#63477)
Add packages/cli-rs, an OpenCode client written in Rust on OpenTUI's Rust crates. It is a client only.
2026-11-22 00:07:01 +01:00

34 lines
1.5 KiB
TypeScript

// Writes crates/local/src/generated/config.rs: the keybind names `cli.json` accepts, in definition order (the
// order Effect Schema decodes them in), and the V1 names and command map the V1 migration reads.
import { Definitions } from "../../../tui/src/config/keybind"
import { TuiKeybind } from "../../../tui/src/config/v1/keybind"
const list = (name: string, doc: string, values: string[]) => [
`/// ${doc}`,
`pub const ${name}: &[&str] = &[`,
...values.map((value) => ` ${JSON.stringify(value)},`),
"];",
"",
]
const commands = Object.entries(TuiKeybind.CommandMap)
const lines = [
"// Generated by script/gen/config.ts from packages/tui/src/config/keybind.ts and v1/keybind.ts. Do not edit.",
"",
...list("KEYBIND_NAMES", "Keybind names of `cli.json`, in definition order.", Object.keys(Definitions)),
...list(
"V1_KEYBIND_NAMES",
"Keybind names of the V1 `tui.json`, in definition order.",
Object.keys(TuiKeybind.Definitions),
),
"/// The V1 `CommandMap`: legacy keybind name to the current name.",
"pub const V1_COMMAND_MAP: &[(&str, &str)] = &[",
...commands.map(([from, to]) => ` (${JSON.stringify(from)}, ${JSON.stringify(to)}),`),
"];",
"",
]
const file = new URL("../../crates/local/src/generated/config.rs", import.meta.url).pathname
await Bun.write(file, lines.join("\n"))
console.log(
`config: ${Object.keys(Definitions).length} keybinds, ${Object.keys(TuiKeybind.Definitions).length} V1 keybinds, ${commands.length} V1 commands`,
)