whook icon indicating copy to clipboard operation
whook copied to clipboard

Improve the `whook create` command

Open nfroidure opened this issue 2 years ago • 0 comments

There is a clear pattern here: https://github.com/nfroidure/whook/blob/2126f07fea694dc7963e79dd91056e57eaec52bd/packages/whook/src/commands/create.ts#L48-L55

We should be able to load all services types from the WHOOK_PLUGINS to help creating handlers smoothly.

It would be easy to get all services names by getting key of Knifecycle initializersStates property but getting the types is a bit more tricky :

  • for constants : get the literal value type (but branded types won't be possible)
  • for services : read the initializer path and find types the initializer return of use type names endind with Service

A temporary solution can be to put any/unknown as the type and let the dev import it since it woul be nice step to just be able to list the services in the CLI selector.

Another option could be to require whook plugins (but more generally any Knifecycle module) to export the list of services they embed with their name/type/path mappings to retrieve something like that: https://github.com/nfroidure/whook/blob/2126f07fea694dc7963e79dd91056e57eaec52bd/packages/whook/src/commands/create.ts#L26C1-L37C3

Finally, retrieving the modules types can be done with this module: https://ts-morph.com/navigation/example

nfroidure avatar Aug 18 '23 15:08 nfroidure