@amritk/mjst 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -0
- package/dist/cli-config.d.ts +25 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2523 -0
- package/dist/load-config.d.ts +6 -0
- package/dist/parse-cli-args.d.ts +7 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @amritk/mjst
|
|
4
|
+
|
|
5
|
+
**Generate TypeScript parsers and type definitions from JSON Schemas.**
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
`@amritk/mjst` is the command-line entry point for [mjst](../../README.md). Point it at a JSON Schema and it produces TypeScript parsers, validators, and type definitions in the directory of your choice.
|
|
21
|
+
|
|
22
|
+
Options can be supplied via CLI flags or a JSON config file. **CLI flags always take precedence over config file values.**
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install --save-dev @amritk/mjst
|
|
30
|
+
# or
|
|
31
|
+
pnpm add -D @amritk/mjst
|
|
32
|
+
# or
|
|
33
|
+
yarn add -D @amritk/mjst
|
|
34
|
+
# or
|
|
35
|
+
bun add -d @amritk/mjst
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The package ships a `mjst` bin that runs under Node ≥ 20 (or Bun), so you can invoke it via `npx mjst`, `pnpm dlx mjst`, `yarn dlx mjst`, `bunx mjst`, or as a script in `package.json`.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### CLI
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx mjst --schema ./schema.json --outDir ./generated
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Config file
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx mjst --config ./mjst.config.json
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> [!NOTE]
|
|
57
|
+
> Validate your config against the bundled JSON Schema: [`config.schema.json`](./config.schema.json)
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Configuration reference
|
|
62
|
+
|
|
63
|
+
<!-- config-table-start -->
|
|
64
|
+
| | Property | CLI Flag | Type | Required | Default | Description |
|
|
65
|
+
|:---:|:---|:---|:---:|:---:|:---:|:---|
|
|
66
|
+
| 📄 | `schema` | `--schema <path>` | `string` | ✅ | — | Path to the JSON Schema file to process. The schema is read, parsed, and used to generate TypeScript source files. |
|
|
67
|
+
| 📁 | `outDir` | `--outDir <dir>` | `string` | ✅ | — | Output directory for generated TypeScript files. The directory is created automatically if it does not exist. Subdirectories are created as needed when a generated file includes a nested path. |
|
|
68
|
+
| 🏷️ | `typesOnly` | `--types-only` | `boolean` | — | `false` | Generate only TypeScript type definitions without parser functions. Useful when you only need the type shapes and do not need runtime validation. |
|
|
69
|
+
| 🔨 | `build` | `--build` | `boolean` | — | `false` | Compile the generated TypeScript files to .js and .d.ts output. A temporary tsconfig is written to the output directory, tsc is invoked, and the intermediate .ts source files are removed when compilation succeeds. |
|
|
70
|
+
| ⚠️ | `logWarnings` | `--log-warnings` | `boolean` | — | `false` | Emit a console.warn in the generated parsers for every input key that is not declared in the schema's properties. Useful for detecting schema drift or unexpected data shapes at runtime. |
|
|
71
|
+
| ⚙️ | `config` | `--config <path>` | `string` | — | — | Path to a JSON config file. Keys match the option names in this schema (schema, outDir, typesOnly, build, logWarnings). CLI flags take precedence over config file values. |
|
|
72
|
+
<!-- config-table-end -->
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Config file examples
|
|
77
|
+
|
|
78
|
+
**Minimal — generate parsers and types**
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"schema": "./schema.json",
|
|
83
|
+
"outDir": "./generated"
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Types only — skip parser functions**
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"schema": "./schema.json",
|
|
92
|
+
"outDir": "./generated",
|
|
93
|
+
"typesOnly": true
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Build — emit `.js` and `.d.ts` instead of `.ts`**
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"schema": "./schema.json",
|
|
102
|
+
"outDir": "./generated",
|
|
103
|
+
"build": true
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Log warnings — warn on unknown input properties**
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"schema": "./schema.json",
|
|
112
|
+
"outDir": "./generated",
|
|
113
|
+
"logWarnings": true
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Scripts
|
|
120
|
+
|
|
121
|
+
| Script | Command |
|
|
122
|
+
|:---|:---|
|
|
123
|
+
| `bun run dev` | `bun run --conditions=development ./src/cli.ts` |
|
|
124
|
+
| `bun run start` | `bun run ./src/cli.ts` |
|
|
125
|
+
| `bun run build` | `bun run build:code && bun run build:types` |
|
|
126
|
+
| `bun run generate-readme` | `bun run generate-readme` |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
[MIT](../../LICENSE)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the CLI tool.
|
|
3
|
+
* These properties map 1:1 with CLI flags and config file keys.
|
|
4
|
+
*/
|
|
5
|
+
export type CliConfig = {
|
|
6
|
+
/** Path to the JSON Schema file to process. */
|
|
7
|
+
readonly schema: string;
|
|
8
|
+
/** Output directory for generated TypeScript files. */
|
|
9
|
+
readonly outDir: string;
|
|
10
|
+
/**
|
|
11
|
+
* When true, only generate TypeScript type definitions without parser functions.
|
|
12
|
+
* Useful when you only need the type shapes and do not need runtime validation.
|
|
13
|
+
*/
|
|
14
|
+
readonly typesOnly?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* When true, compile the generated TypeScript files to .js and .d.ts output.
|
|
17
|
+
* The .ts source files are removed after compilation.
|
|
18
|
+
*/
|
|
19
|
+
readonly build?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* When true, the generated parsers emit a console.warn for every input key
|
|
22
|
+
* that is not declared in the schema's properties.
|
|
23
|
+
*/
|
|
24
|
+
readonly logWarnings?: boolean;
|
|
25
|
+
};
|
package/dist/cli.d.ts
ADDED