toss / es-toolkit

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.
https://es-toolkit.slash.page
Other
6.25k stars 263 forks source link

docs: automate the English documentation #472

Closed dayongkr closed 1 week ago

dayongkr commented 1 week ago

Description

I’ve implemented an automation feature using VitePress’s dynamic routes and comment-parser with @typescript-eslint/parser to generate documentation(only reference/array).

The approach is as follows:

  1. Dynamic routes and Node.js fs module are used to generate paths for each function (reference/array/[function].md, reference/array/[function].paths.mts are for Dynamic routes).
  2. The source files of each function are parsed with comment-parser to extract JSDoc comments (e.g., function descriptions, parameter details) and with @typescript-eslint/parser to retrieve Function signatures and types.
  3. The extracted data is then used to generate content strings through abstracted functions.

This setup allows for the English documentation to be created by simply adding a folder and two files for Dynamic routes per function category.

Before proceeding further, I’ve opened a PR to get feedback on the current implementation way. I would appreciate your feedback.

Rough flow chart

Flowchart drawio (1)

vercel[bot] commented 1 week ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
es-toolkit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 4, 2024 1:51am
codecov-commenter commented 1 week ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.71%. Comparing base (3a6cb36) to head (229181a). Report is 12 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/toss/es-toolkit/pull/472/graphs/tree.svg?width=650&height=150&src=pr&token=8N5S3AR3C7&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toss)](https://app.codecov.io/gh/toss/es-toolkit/pull/472?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=toss) ```diff @@ Coverage Diff @@ ## main #472 +/- ## ========================================== - Coverage 99.78% 99.71% -0.07% ========================================== Files 171 178 +7 Lines 1366 1382 +16 Branches 364 366 +2 ========================================== + Hits 1363 1378 +15 - Misses 2 3 +1 Partials 1 1 ```
raon0211 commented 1 week ago

This is really impressive—thank you so much! I have a few thoughts:

dayongkr commented 1 week ago

First of all, thank you for your feedback. Here are my thoughts in response:

  1. I chose dynamic routes for full automation, as using a draft-based approach would still require modifications if the type changes. However, I completely agree that the draft approach would be more adaptable. I also could find many edge cases when I implemented this.
  2. Both cases you mentioned are fully supported at now. Please refer to the images below for reference. Additionally, it also supports scenarios with multiple jsDOCs.

Screenshot 2024-09-04 at 10 45 29 AM Screenshot 2024-09-04 at 10 46 07 AM

I briefly looked into @deno/doc, and it seems quite powerful. However, it doesn’t provide support for the range value, meaning that I would need to generate the types manually through AST. This adds a lot of branching and code, which raises concerns regarding maintainability and stability. But it still looks great!

By the way, the development process itself was fun. So, I'm totally fine with closing this PR, merging this codes into the main branch, and then finding areas for improvement later on!

Thanks!

dayongkr commented 1 week ago

This issue is resolved by a9e7edde14e6f2b5a1e61262344de366879a9aee.

So I close this PR!