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): CLI generated types #3453

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Conversation

Fleny113
Copy link
Contributor

@Fleny113 Fleny113 commented Feb 22, 2024

This pr adds the code to auto-generate the typings based on the desiredProprieties, this (will) build on the work already been done in #3255.

Currently the code has a bunch of FIXME, TODO and testing stuff that I use when testing the code

To test the code, make use you are in the packages/discordeno directory (there are hard-coded path at the moment) then build the source, and run node ./bin/discordeno.js, then in the packages/bot/src/transformers there will be a transformers.test.generated.ts along side the transformers.generated.ts, the 2 file exist to be confronted1. The CLI builds that generated.ts file based on the packages/discordeno/src/bin/transformers.ts file, in there, all the transformer proprieties are present along their metadata like comment, if they are optional, etc

The generated file uses inline import functions to import the types from other packages, because it was simpler to code

Currently my objective is getting something that works, then I will cleanup the generation code and provably move it to a different file rather than keeping it all in the src/bin/index.ts file

This pr also removes the internalABC proprieties that were in some objects, there are now "untyped" in the publicly exposed type, a user COULD override them with a customizer, so it might get reverted this change

TODO

  • Use the TS compiler to pick the existing types and dump them in a single JS object
  • Create the generator for the interfaces (without desired proprieties)
    • Handle the name and types
    • Handle optional types
    • Handle array types (without having to specify it in the type itself)
    • Handle the TSDoc comment(s)
  • Handle the desired proprieties
    • Disable the desired proprieties for transformers that do not support it (Activity, Team, ecc)
    • Make sure when all proprieties are deleted, it uses object not an empty interface (that equals to NonNullable<unknown> so string | number | object | symbol | bigint | ...)
    • Implement desired proprieties modes
      • Delete the propriety
      • Type the propriety as optional
      • Type the propriety as never
      • Add never in a union
      • Maybe others (??) Maybe remove some (??)
    • Source the desired proprieties list from the config file
      • discordeno.config.js (or .ts (??))
      • package.json (??)
      • json config file (??)
    • Autogenerate the desired propriety list (??, maybe at least the type?)
    • Make sure "desired propriety dependencies" work2
    • Fix bugs if found
  • Find a way to generate code with Deno (BLOCKING)3
  • Remove the hard code file path
  • Fix TODO(s) and FIXME(s) if still present
  • Try to make the DX for editing the src/bin/transformers.ts file or the transformers is not miserable
  • Test in actual codebases [will require help]
  • Code cleanup

Everything that is marked with a ?? in the TODO means that it's not sure that it will get done

closes #3190
closes #2983

Footnotes

  1. While eslint can be disabled with a comment, prettier can not, so each time a commit is made the transformers.generated.ts file gets formatted, so to compare the files and not having to clean with prettier, just run it on the other file as well

  2. Currently, I have a dependency array that can be used to disable a propriety if it does not have it's dependencies, eg. user.tag depends on user.username and user.discrminator, interaction.reply depends on interaction.token, interaction.id and interaction.type

  3. Since Deno does not use the node_modules folder there ia the need to find another way to source generate stuff under a Deno environment

@github-actions github-actions bot added w-unverified This has not been verified pkg-all Affects every package pkg-bot Affects the bot package t-feat A new feature labels Feb 22, 2024
@Fleny113 Fleny113 self-assigned this Feb 22, 2024
@AwesomeStickz AwesomeStickz added w-verified This had been verified and removed w-unverified This has not been verified labels Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg-all Affects every package pkg-bot Affects the bot package t-feat A new feature w-verified This had been verified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CLI] npx discordeno generate [Bot] Customize Typings Based on DesiredProperties
2 participants