Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cli overhaul with oclif #1966

Draft
wants to merge 25 commits into
base: next
Choose a base branch
from
Draft

feat: cli overhaul with oclif #1966

wants to merge 25 commits into from

Conversation

arthurfiorette
Copy link
Collaborator

@arthurfiorette arthurfiorette commented May 23, 2024

This PR adds a new cli under the name of tjsg. I kept the previous ts-json-schema-generator intact to keep compatibility with older versions and avoid another breaking release.

Also updated readme and set up oclif to automatically update some readme sections to keep up with cli changes.

New --flags were added and some unused ones were removed.

Some outputs:

$ tjsg --help
Generate JSON schema from your Typescript sources

VERSION
  ts-json-schema-generator/2.0.0 wsl-x64 node-v20.13.1

USAGE
  $ tjsg [COMMAND]

COMMANDS
  autocomplete  Display autocomplete installation instructions.
  generate      Generate JSON schema from your Typescript sources
  help          Display help for tjsg.

$ tjsg generate --help
Generate JSON schema from your Typescript sources

USAGE
  $ tjsg generate [PATH] [-t <value>] [--top-ref] [-i <value>] [-p <value>] [-e all|none|export] [-j
    none|basic|extended] [--markdown-description] [--sort-props] [--strict-tuples] [--type-check] [--ref-encode]
    [--additional-properties] [--functions fail|comment|hide] [--minify] [-o <value>] [--extra-tags <value>]
    [--discriminator-type json-schema|open-api]

ARGUMENTS
  PATH  Source file path

FLAGS
  -e, --expose=<option>              [default: export] Type exposing
                                     <options: all|none|export>
  -i, --id=<value>                   $id for generated schema
  -j, --jsdoc=<option>               [default: extended] Read JsDoc annotations
                                     <options: none|basic|extended>
  -o, --out=<value>                  Set the output file (default: stdout)
  -p, --tsconfig=<value>             Your tsconfig.json to load entry files and compilation settings
  -t, --type=<value>                 Type name
      --additional-properties        Allow additional properties for objects with no index signature
      --discriminator-type=<option>  [default: json-schema] Type of discriminator to use
                                     <options: json-schema|open-api>
      --extra-tags=<value>...        [default: ] Provide additional validation keywords to include
      --functions=<option>           [default: comment] How to handle functions. `fail` will throw an error. `comment` will
                                     add a comment. `hide` will treat the function like a NeverType or HiddenType.
                                     <options: fail|comment|hide>
      --markdown-description         Generate `markdownDescription` in addition to `description`. Implies --jsdoc=extended
      --minify                       Minify generated schema
      --[no-]ref-encode              Encode references
      --[no-]sort-props              Makes the schema stable by sorting properties
      --strict-tuples                Do not allow additional items on tuples
      --[no-]top-ref                 Create a top-level $ref definition
      --[no-]type-check              Type checks to improve performance

DESCRIPTION
  Generate JSON schema from your Typescript sources

EXAMPLES
  Analyzes src/types.ts using tsconfig.json and writes the schema to schema.json.

    $ tjsg generate -f tsconfig.json -o schema.json src/types.ts
📦 Published PR as canary version: 2.2.1--canary.1966.fab4d27.0

✨ Test out this PR locally via:

npm install ts-json-schema-generator@2.2.1--canary.1966.fab4d27.0
# or 
yarn add ts-json-schema-generator@2.2.1--canary.1966.fab4d27.0

@arthurfiorette arthurfiorette requested a review from domoritz May 23, 2024 18:43
@arthurfiorette arthurfiorette self-assigned this May 23, 2024
@arthurfiorette
Copy link
Collaborator Author

arthurfiorette commented May 23, 2024

Actually, there's no way to run these new binaries when there's still an entry to ts-json-schema-generator in the package.json's bin field. (Because it gets chosen first as it equals to the name of the package)

This probably will force us to remove the previous binary entirely and probably release another major version (v3.0.0)

@arthurfiorette
Copy link
Collaborator Author

Since oclif has commands support (bin generate, bin help, bin autocomplete...), it cannot have a dafault behavior anymore (bin by itself will only print the error message.)

I reduced the cli to only tjsg because writing ts-json-schema-generator generate would be too verbose in my opinion, but I can rename it back if you want to.

@arthurfiorette
Copy link
Collaborator Author

https://github.com/intuit/auto has a git check that prevents releasing when there are changed files locally, and as there's no current way to remove that behavior (would need to open a issue first), every time the commands/generate.ts file gets changed, running yarn build is required to avoid failing the Publish Auto CI.

@domoritz domoritz changed the title Cli overhaul with oclif feat: Cli overhaul with oclif May 23, 2024
@domoritz
Copy link
Member

What do you think about ts-js-gen, tsjsg or ts-jsg instead?

Also, I am not a fan of having to type generate when autocomplete is not something I really care about 99% of the time. I know you said we can't easily but I would strongly prefer that and also not needing a major version release.

@arthurfiorette
Copy link
Collaborator Author

What do you think about ts-js-gen, tsjsg or ts-jsg instead?

ts-json is also a good candidate. Please choose whatever you like :)

@domoritz
Copy link
Member

I think I'd prefer to keep the current name since it's used and I never write it manually anyway. Having the cli name be the same as the package makes it very clear.

@arthurfiorette
Copy link
Collaborator Author

arthurfiorette commented May 24, 2024

Ok, ts-json-schema-generator generate? Oclif has support for aliases, so we could set up ts-json-schema-generator generate and tjsg generate. What do you think?

We could also define ts-json-schema-generator to always prepend generate so it behaves exaclty like before.

  • ts-json-schema-generator (only generates)
  • tjsg generate generates
  • tjsg autocomplete and so on...

However I'm almost sure I cannot just "transpile" the previous CLI to this new one without any breaking change. Is releasing v3.0.0 a bad thing? it will only consist of argument changes that can be fixed up in ~10s.

@domoritz
Copy link
Member

A major release is some work here and then in the repos that use the schema generator. Not a huge deal but we should minimize the changes so I like your proposal.

@arthurfiorette arthurfiorette changed the title feat: Cli overhaul with oclif feat: cli overhaul with oclif May 27, 2024
@arthurfiorette arthurfiorette marked this pull request as draft May 29, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants