refactor: use ordana for cli args parsing and generate docs#19436
refactor: use ordana for cli args parsing and generate docs#19436sapphi-red wants to merge 3 commits intovitejs:mainfrom
Conversation
|
Ah, I forgot that I have to implement case conversion. |
|
Might also need to double check About the docs generation, just curious, but couldn't we parse the current CLI output (invoked via child process) and try to format that as markdown instead? I'm a bit worried that we're relying on an external package for an opinionated markdown output. |
Actually
I guess it's possible, but I'm not sure if it's easy to do. The
Instead of returning a markdown output, I can also make the package return the needed information and move some function in https://github.com/sapphi-red/ordana/blob/main/packages/gen-docs/src/docs.ts to this repo if that's preferred. |
Ah forgot about that. Thanks for testing it for Different topic but reading the code that handles
Figuring out the common double-space index shouldn't be too hard I think, but yeah it'll take a bit of code to work.
I was thinking it could return a structured output instead, e.g. a metadata object that contains an array of option settings, array of commands supported, etc. The we could use that to construct markdown, which shouldn't be too hard. But I think we can still try your method if you'd like though, for me I don't think we have to change it for now. |
Yeah, I don't have strong opinion of using
I was thinking that this would be needed anyways so I'll do that later 👍 I found putting flags before the subcommands (e.g. |
I tried supporting this case, but realized it's hard to do without greedy matching (example case, cac's implementation) 🫠. |
Description
The cli document can now be generated from the CLI options.
To achieve that, I made a cli argument parser library named ordana that uses
util.parseArgsinternally.package size
Since
util.parseArgsis not supported by Node 18.0.0, I had to install a polyfill for it. That makes the package size bigger than before. But once we drop support for Node 18.0-18.3, that won't be needed and the package size will be slightly smaller.package size
before
after
when the polyfill is removed
parse behavior differences
ordana parses the arguments differently from cac in some cases, but I guess that's fine. (I can tweak the behavior if needed)
For example,
vite -c ./vite.config-url-base.js buildvite devatbuildas root dir withvite.config-url-base.jsconfigvite buildat default root dir withvite.config-url-base.jsconfigvite --help buildvitevite buildvite build --unknown --help--unknownis unknownvite buildhelp message diff
before


after

