typebox-cli
Advanced tools
Comparing version
import process from "node:process"; | ||
import { program } from "commander"; | ||
import { program } from "./program.js"; | ||
export default function main(argv = process.argv) { | ||
@@ -4,0 +4,0 @@ return program.parse(argv); |
{ | ||
"name": "typebox-cli", | ||
"version": "1.0.2-dev", | ||
"version": "1.0.3-dev", | ||
"description": "CLI tool for various TypeBox and JSON Schema operations", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gsuess/typebox-cli" | ||
}, | ||
"main": "dist/index.js", | ||
@@ -6,0 +10,0 @@ "bin": { |
@@ -17,11 +17,74 @@ # TypeBox CLI | ||
Convert TypeScript Types to TypeBox schema: | ||
#### Convert TypeScript types to TypeBox Schema | ||
Input file (i.e. `types.ts`): | ||
```ts | ||
export type T = "test"; | ||
``` | ||
Run TypeBox Codegen: | ||
```bash | ||
typebox codegen TypeBox --source types.ts > typebox.ts | ||
typebox codegen TypeBox --source types.ts | ||
``` | ||
Outputs: | ||
```ts | ||
import { Type, Static } from '@sinclair/typebox' | ||
export type T = Static<typeof T> | ||
export const T = Type.String() | ||
``` | ||
#### Convert TypeBox Schema into JSON schema | ||
Input file (i.e. `typebox.ts`): | ||
```ts | ||
import { Type } from "@sinclair/typebox"; | ||
export const T = Type.String(); | ||
``` | ||
Run JSON Schema extraction: | ||
```bash | ||
typebox extract json --module typebox.ts -e T | ||
``` | ||
Outputs: | ||
```json | ||
{ | ||
"$id": "T", | ||
"type": "string" | ||
} | ||
``` | ||
## Reference | ||
### Commands | ||
```bash | ||
# Extract - Extract JSON schema from exported TypeBox variables: | ||
typebox extract json --module <module path> | ||
# Codegen -- Generate Schema from either TypeScript types (using --source) or TypeBox schema (using --module): | ||
typebox codegen <model-name> --source <source file> # Generate from TypeScript Types. | ||
typebox codegen <model-name> --module <module path> # Generate from exported TypeBox Schema values. | ||
# List available Codegen models: | ||
typebox list | ||
# Misc | ||
typebox --version # Display current typebox version. | ||
typebox --help # Help | ||
``` | ||
### Dependencies | ||
`typebox-cli` is based on these packages: | ||
- [TypeBox](https://github.com/sinclairzx81/typebox) - Json Schema Type Builder with Static Type Resolution for TypeScript | ||
- [TypeBox Codegen](https://github.com/sinclairzx81/typebox-codegen) - Code Generation Tools for TypeBox | ||
- [jiti](https://github.com/unjs/jiti) - Module Loading | ||
- [Commander](https://github.com/tj/commander.js) - CLI Interface | ||
## License | ||
[MIT](LICENSE) |
Sorry, the diff of this file is not supported yet
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
17357
10.18%89
229.63%0
-100%