From 9c13f0c0e5ff756009eb36837911f943c0045283 Mon Sep 17 00:00:00 2001 From: Arthur Fiorette Date: Thu, 23 May 2024 15:23:06 -0300 Subject: [PATCH 01/24] cli --- README.md | 289 +++-- bin/dev.js | 8 + bin/run.js | 8 + commands/generate.ts | 168 +++ oclif.manifest.json | 169 +++ package.json | 123 ++- ts-json-schema-generator.ts | 5 + tsconfig.cjs.json | 2 +- tsconfig.json | 2 +- yarn.lock | 2035 ++++++++++++++++++++++++++++++++++- 10 files changed, 2660 insertions(+), 149 deletions(-) create mode 100755 bin/dev.js create mode 100755 bin/run.js create mode 100644 commands/generate.ts create mode 100644 oclif.manifest.json diff --git a/README.md b/README.md index f2913fe22..4f01b6301 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ts-json-schema-generator +

ts-json-schema-generator

![Test](https://github.com/vega/ts-json-schema-generator/workflows/Test/badge.svg) [![codecov](https://codecov.io/gh/vega/ts-json-schema-generator/branch/master/graph/badge.svg)](https://codecov.io/gh/vega/ts-json-schema-generator) @@ -6,70 +6,201 @@ Extended version of [https://github.com/xiag-ag/typescript-to-json-schema](https://github.com/xiag-ag/typescript-to-json-schema). +--- + +- [Inspiration](#inspiration) +- [CLI Usage](#cli-usage) + - [Options](#options) +- [`tjsg autocomplete [SHELL]`](#tjsg-autocomplete-shell) +- [`tjsg generate`](#tjsg-generate) +- [`tjsg help [COMMAND]`](#tjsg-help-command) +- [Current state](#current-state) +- [Contributors](#contributors) +- [Programmatic Usage](#programmatic-usage) + - [Custom formatting](#custom-formatting) + - [Custom parsing](#custom-parsing) +- [Run locally](#run-locally) +- [Publish](#publish) + +
+ +## Inspiration + Inspired by [`YousefED/typescript-json-schema`](https://github.com/YousefED/typescript-json-schema). Here's the differences list: - this implementation avoids the use of `typeChecker.getTypeAtLocation()` (so probably it keeps correct type aliases) - processing AST and formatting JSON schema have been split into two independent steps - not exported types, interfaces, enums are not exposed in the `definitions` section in the JSON schema -## Contributors - -This project is made possible by a [community of contributors](https://github.com/vega/ts-json-schema-generator/graphs/contributors). We welcome contributions of any kind (issues, code, documentation, examples, tests,...). Please read our [code of conduct](https://vega.github.io/vega/about/code-of-conduct). +
## CLI Usage -Run the schema generator with npx: - -```bash -npx ts-json-schema-generator --path 'my/project/**/*.ts' --type 'My.Type.Name' + + +```sh-session +$ npm install -g ts-json-schema-generator +$ tjsg COMMAND +running command... +$ tjsg (--version|-v) +ts-json-schema-generator/2.0.0 linux-x64 node-v20.13.1 +$ tjsg --help [COMMAND] +USAGE + $ tjsg COMMAND +... ``` -Or install the package and then run it - -```bash -npm install --save ts-json-schema-generator -./node_modules/.bin/ts-json-schema-generator --path 'my/project/**/*.ts' --type 'My.Type.Name' -``` + Note that different platforms (e.g. Windows) may use different path separators so you may have to adjust the command above. Also note that you need to quote paths with `*` as otherwise the shell will expand the paths and therefore only pass the first path to the generator. +
+ ### Options + + +- [`tjsg autocomplete [SHELL]`](#tjsg-autocomplete-shell) +- [`tjsg generate`](#tjsg-generate) +- [`tjsg help [COMMAND]`](#tjsg-help-command) + +## `tjsg autocomplete [SHELL]` + +Display autocomplete installation instructions. + +``` +USAGE + $ tjsg autocomplete [SHELL] [-r] + +ARGUMENTS + SHELL (zsh|bash|powershell) Shell type + +FLAGS + -r, --refresh-cache Refresh cache (ignores displaying instructions) + +DESCRIPTION + Display autocomplete installation instructions. + +EXAMPLES + $ tjsg autocomplete + + $ tjsg autocomplete bash + + $ tjsg autocomplete zsh + + $ tjsg autocomplete powershell + + $ tjsg autocomplete --refresh-cache +``` + +_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v3.0.18/src/commands/autocomplete/index.ts)_ + +## `tjsg generate` + +Generate JSON schema from your Typescript sources + +``` +USAGE + $ tjsg generate [-p ] [-t ] [-i ] [-f ] [-e all|none|export] [-j + none|basic|extended] [--markdown-description] [--functions fail|comment|hide] [--minify] [--unstable] + [--strict-tuples] [--no-top-ref] [--no-type-check] [--no-ref-encode] [-o ] [--validation-keywords ] + [--additional-properties] + +FLAGS + -e, --expose=