Skip to content

Commit 262c110

Browse files
feat: npx @graplix/codegen
1 parent d6df26b commit 262c110

9 files changed

Lines changed: 52 additions & 29 deletions

File tree

.changeset/afraid-gifts-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graplix/codegen": minor
3+
---
4+
5+
feat: npx @graplix/codegen

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ From `biome.json`:
142142
- CLI supports config discovery via `cosmiconfig`.
143143
- Supported config names include `graplix.codegen.*` and `graplix-codegen.config.*`.
144144
- CLI precedence: command-line args override config values.
145-
- Prefer `defineConfig` from `@graplix/codegen` for typed config files.
145+
- Prefer JSON config with `$schema` for editor-validated codegen settings.
146146

147147
## Tech Spec Workflow
148148

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Runtime evaluator for schema-defined relations.
3131
TypeScript generator for Graplix schemas.
3232

3333
- Generates typed helpers from `.graplix` input.
34+
- Run from npm with `npx @graplix/codegen`.
3435
- Supports mapper configuration and config-file discovery.
3536
- README: [`packages/codegen/README.md`](packages/codegen/README.md)
3637

packages/codegen/README.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ Generates TypeScript helpers from Graplix schema files.
55
## CLI
66

77
```bash
8-
yarn workspace @graplix/codegen build
9-
yarn workspace @graplix/codegen codegen ./schema.graplix
8+
npx @graplix/codegen ./schema.graplix
109
```
1110

1211
With mapper overrides:
1312

1413
```bash
15-
yarn workspace @graplix/codegen codegen ./schema.graplix ./schema.generated.ts --mapper user=./models#User --mapper repository=./models#Repository
14+
npx @graplix/codegen ./schema.graplix ./schema.generated.ts --mapper user=./models#User --mapper repository=./models#Repository
1615
```
1716

1817
Config files are also supported (`cosmiconfig`):
@@ -21,10 +20,15 @@ Config files are also supported (`cosmiconfig`):
2120
- `graplix-codegen.config.json|yaml|yml|js|cjs|mjs|ts|cts|mts`
2221
- `package.json` with `"graplix-codegen"` key
2322

23+
JSON Schema for editor auto-complete/validation:
24+
25+
- `https://unpkg.com/@graplix/codegen@latest/schema.json`
26+
2427
Example (`graplix.codegen.json`):
2528

2629
```json
2730
{
31+
"$schema": "https://unpkg.com/@graplix/codegen@latest/schema.json",
2832
"schema": "./schema.graplix",
2933
"output": "./schema.generated.ts",
3034
"mappers": {
@@ -35,20 +39,6 @@ Example (`graplix.codegen.json`):
3539

3640
CLI args override config values.
3741

38-
Typed config helper:
39-
40-
```ts
41-
import { defineConfig } from "@graplix/codegen";
42-
43-
export default defineConfig({
44-
schema: "./schema.graplix",
45-
output: "./schema.generated.ts",
46-
mappers: {
47-
user: "./models#User",
48-
},
49-
});
50-
```
51-
5242
## Programmatic API
5343

5444
```ts

packages/codegen/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
"types": "./dist/index.d.mts",
2525
"import": "./dist/index.mjs",
2626
"require": "./dist/index.cjs"
27-
}
27+
},
28+
"./schema.json": "./schema.json"
2829
},
2930
"main": "./dist/index.cjs",
3031
"module": "./dist/index.mjs",
3132
"types": "./dist/index.d.mts",
32-
"bin": {
33-
"graplix-codegen": "./dist/cli.mjs"
34-
},
33+
"bin": "./dist/cli.mjs",
3534
"files": [
36-
"dist"
35+
"dist",
36+
"schema.json"
3737
],
3838
"scripts": {
3939
"build": "tsdown",

packages/codegen/schema.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://unpkg.com/@graplix/codegen@latest/schema.json",
4+
"title": "@graplix/codegen configuration",
5+
"description": "Configuration for Graplix TypeScript code generation.",
6+
"type": "object",
7+
"properties": {
8+
"$schema": {
9+
"type": "string",
10+
"description": "Optional schema URL for editor auto-completion and validation."
11+
},
12+
"schema": {
13+
"type": "string",
14+
"description": "Path to the .graplix schema file."
15+
},
16+
"output": {
17+
"type": "string",
18+
"description": "Output file path for generated TypeScript."
19+
},
20+
"mappers": {
21+
"type": "object",
22+
"description": "Map Graplix type names to TypeScript type references.",
23+
"additionalProperties": {
24+
"type": "string"
25+
}
26+
}
27+
},
28+
"required": ["schema"],
29+
"additionalProperties": false
30+
}

packages/codegen/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface ResolvedArguments {
2222

2323
function fail(message: string): never {
2424
throw new Error(
25-
`${message}\nUsage: graplix-codegen [schema.graplix] [output.ts] [--config graplix.codegen.json] [--mapper Type=./module#Type]`,
25+
`${message}\nUsage: npx @graplix/codegen [schema.graplix] [output.ts] [--config graplix.codegen.json] [--mapper Type=./module#Type]`,
2626
);
2727
}
2828

packages/codegen/src/config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import type { MapperConfig } from "./generate";
22

33
export interface CodegenConfig {
4+
readonly $schema?: string;
45
readonly schema: string;
56
readonly output?: string;
67
readonly mappers?: MapperConfig;
78
}
8-
9-
export function defineConfig(config: CodegenConfig): CodegenConfig {
10-
return config;
11-
}

packages/codegen/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { type CodegenConfig, defineConfig } from "./config";
1+
export type { CodegenConfig } from "./config";
22
export {
33
type GenerateTypeScriptFromFileOptions,
44
type GenerateTypeScriptOptions,

0 commit comments

Comments
 (0)