Skip to content

Commit c7b53df

Browse files
tmmampagent
andauthored
feat(zero-swift): build the CLI on incur (#5)
codegen gets an option per config key; the schema module option is --schema-file because incur reserves --schema, and --schema <path> still works. Errors are a code and a message. Documents the config keys. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: Amp <amp@ampcode.com>
1 parent db341c7 commit c7b53df

7 files changed

Lines changed: 325 additions & 113 deletions

File tree

‎.changeset/cli-incur.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'zero-swift': minor
3+
---
4+
5+
The CLI is built on [incur](https://github.com/wevm/incur). Errors print a code and a message and exit 1. `--json` prints results as JSON, `--llms` prints a manifest for coding agents, and `skills add` installs the commands as an agent skill. `codegen` has an option for every config key, such as `--type-prefix` and `--access`. The schema module option is now `--schema-file`, because incur reserves `--schema`; `--schema <path>` still works. The config keys are now documented in the README.

‎packages/zero-swift-cli/README.md‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,28 @@ npx zero-swift codegen --check # fails when the output is out of date
3737
`Int`; it must then hold integers. For a `json<T>()` column whose `T` is a
3838
plain object or a literal union, the tool generates a `Codable` type.
3939

40-
`--schema`, `--out`, and `--config` override the config file.
40+
Every key is optional:
41+
42+
| Key | Default | Meaning |
43+
| ----------------------------- | ------------------- | ----------------------------------------- |
44+
| `schema` | `schema.ts` | The TypeScript schema module |
45+
| `export` | `schema` | The module export that holds the schema |
46+
| `output` | `Schema.swift` | The Swift file to write |
47+
| `schemaName` | `app` | The `ZeroSchema` static, `ZeroSchema.app` |
48+
| `zql` | `zql` | The global query builder, of type `ZQL` |
49+
| `typePrefix` | none | Prepended to every generated type name |
50+
| `access` | `public` | `public` or `internal` |
51+
| `tables.<t>.type` | `<t>` in PascalCase | The row struct's name |
52+
| `tables.<t>.columns.<c>.type` | from the schema | `int` or `double` |
53+
54+
Rename a row struct whose name clashes with a type you use. A table named
55+
`list` generates `struct List`, which hides SwiftUI's `List`; set
56+
`tables.list.type` to `NoteList`, or set a `typePrefix`.
57+
58+
Each config key has an option, such as `--schema-file`, `--out`,
59+
`--type-prefix`, and `--access`, that overrides it. `--config` picks the
60+
config file. Run `npx zero-swift codegen --help` for the full list.
61+
`--schema <path>` from 0.1.0 still works, as `--schema-file`.
4162

4263
## `zero-swift drift record`
4364

@@ -60,3 +81,11 @@ The samples module's default export holds:
6081

6182
Record again whenever either side changes. `--check` fails when the recorded
6283
file is out of date.
84+
85+
## Output and agents
86+
87+
The CLI is built on [incur](https://github.com/wevm/incur). Errors print a
88+
code and a message and exit 1, with no stack trace. `--json` (or `--format`)
89+
prints the result as JSON, for scripts and CI. `--llms` prints a manifest of
90+
the commands for a coding agent, and `npx zero-swift skills add` installs
91+
them as an agent skill.

‎packages/zero-swift-cli/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
},
2323
"scripts": {
24-
"build": "esbuild src/bin.ts --bundle --platform=node --format=esm --target=node22 --splitting --outdir=dist --external:@rocicorp/zero --external:typescript",
24+
"build": "esbuild src/bin.ts --bundle --platform=node --format=esm --target=node22 --splitting --outdir=dist --external:@rocicorp/zero --external:typescript --external:incur",
2525
"test": "vitest run",
2626
"generate": "UPDATE_GENERATED=1 vitest run",
2727
"check-types": "tsc",
@@ -31,6 +31,7 @@
3131
"version-packages": "cd ../.. && pnpm dlx @changesets/cli@3.0.3 version && jq -r .version packages/zero-swift-cli/package.json > swift/VERSION"
3232
},
3333
"dependencies": {
34+
"incur": "0.7.1",
3435
"typescript": "6.0.3"
3536
},
3637
"devDependencies": {

‎packages/zero-swift-cli/src/bin.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
#!/usr/bin/env node
2-
import {main, UsageError} from './cli.ts';
2+
import {cli, legacyArgv} from './cli.ts';
33

4-
try {
5-
process.exitCode = await main(process.argv.slice(2));
6-
} catch (e) {
7-
if (!(e instanceof UsageError)) {
8-
throw e;
9-
}
10-
process.stderr.write(`zero-swift: ${e.message}\n`);
11-
process.exitCode = 1;
12-
}
4+
await cli.serve(legacyArgv(process.argv.slice(2)));

0 commit comments

Comments
 (0)