ts-rs icon indicating copy to clipboard operation
ts-rs copied to clipboard

CLI

Open gustavo-shigueo opened this issue 8 months ago • 7 comments

I'm copying the original cli PR into a new one for a couple of reasons:

  • The thread on the old one is VERY long and is getting hard to follow
  • Whoever is using the account that opened that PR (if anyone) probably doesn't wanna receive notifications about it

Closes #133 Closes #54 Closes #408

Todo

  • [x] Find a way to only run ts-rs tests through this CLI
    • Done by gating the generation of tests
      • Added a feature flag called export to ts-rs that re-enables test generation.
      • This feature is always enabled when using this CLI
  • [x] Explore a way of generating an index.ts file to reexport all the generated types
    • During export, generate a metadata file to list all types and where they are exported to
      • In the CLI, use the metadata file to create the index.ts file
      • Gate the generation of this file behind a feature flag named generate-metadata
  • [x] A configuration file so the user doesn't have to pass the flags every time
    • [x] Add config flag to pass the path to the file?
    • [x] Add init subcommand to help create the config file
  • [ ] Discuss other features of the CLI
  • [ ] When we consider it ready, it would be interesting to also make it available through cargo binstall

Feature wishlist

  • [x] Customize representations (e.g number vs bigint) (@NyxCode) (being worked on in #334)
  • [x] Load configuration from configfile (@NyxCode) (being worked on in #334)
  • [x] (maybe) Combine multiple types in one file? (@NyxCode) (#316)
  • [x] (maybe) generate index.ts file, re-exporting types (@NyxCode) (See explanation above)

Checklist

  • [x] I have followed the steps listed in the Contributing guide.
  • [ ] If necessary, I have added documentation related to the changes made.
  • [ ] I have added or updated the tests related to the changes made.

gustavo-shigueo avatar Apr 05 '25 19:04 gustavo-shigueo

The implementation of the CLI is a breaking change for anyone who uses --no-default-features to disable serde-compat as that will also disable the new export feature, preventing the test functions that export the types from being generated

gustavo-shigueo avatar Apr 05 '25 21:04 gustavo-shigueo

Hey @NyxCode, I merged #334 into the CLI and added a command to generate a default config file. I also removed the --merge flag, as I believe that #316 already does that well enough, especially when combined with #399.

What do you think of the current state of the CLI? Are there other features you want to include?

gustavo-shigueo avatar Apr 05 '25 22:04 gustavo-shigueo

Hey @NyxCode! It looks llike I no longer have write access to ts-rs. Did something happen with you or is this because the repo is in the Aleph Alpha org?

gustavo-shigueo avatar Apr 07 '25 18:04 gustavo-shigueo

@gustavo-shigueo Very weird - certainly nothing I did. I'll figure it out asap, sorry about that.

NyxCode avatar Apr 08 '25 11:04 NyxCode

No problem. I imagine someone at the org level did some kind of security audit and went "who tf is this random dude with access to one of our repos" lol

gustavo-shigueo avatar Apr 08 '25 11:04 gustavo-shigueo

Is there some work that I could contribute to this to help this PR get merged? I'm needing a way to generate barrel files (those index.ts files that reexport everything).

PS: NyxCode. Nice name. :3

CriusNyx avatar Jun 21 '25 19:06 CriusNyx

Hello @CriusNyx , I'm not quite sure if/when this might be merged, as there are a few possible concerns about it:

  • @NyxCode has raised some concerns in #382
  • This PR is a breaking change for anyone using --no-default-features to disable serde-compat
  • We are not yet sure if there are more features we want to add
  • We haven't documented or tested the CLI very thoroughly yet - we did have someone use it and report good results in #408 though

All that being said, you can install it with the following command: cargo install --git https://github.com/Aleph-Alpha/ts-rs --branch feat/cli ts-rs-cli and then use a ts-rs export --index to achieve the behavior you need

gustavo-shigueo avatar Jun 22 '25 00:06 gustavo-shigueo