Skip to content

feat(web): add web generator #285

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat(web): add web generator #285

wants to merge 4 commits into from

Conversation

avivkeller
Copy link
Member

@avivkeller avivkeller commented May 28, 2025

Fixes #7.

This PR adds the web generator.

Tasks / Issues

P1 – Must Complete Before Merge

  • Add more items (anyone can do this as they review1)

P2 – Must complete before migration

P3 – Can Be Done in a Follow-up

  • Remove mustache dependency
  • Add more items (anyone can do this as they review1)

Get a preview

node bin/cli.mjs generate -t orama-db -i "/node/doc/api/*.md" -o "./out" # If you want search functionality
node bin/cli.mjs generate -t web -i "/node/doc/api/*.md" -o "./out" --index "/node/doc/api/index.md" # Specifying `--index` is optional, but recommended
npx serve out # You can serve the output, or just open one of the files in your browser. Serving is required for using search.

Footnotes

  1. Add things as they appear, or leave review comments. 2 3

@codecov-commenter
Copy link

codecov-commenter commented May 28, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
165 1 164 0
View the top 1 failed test(s) by shortest run time
test::should process entries and include JSX wrapper elements
Stack Traces | 0.00573s run time
Error [ERR_TEST_FAILURE]: Missing "Article". Found: NotificationProvider, NavBar
    at async Promise.all (index 0) {
  code: 'ERR_TEST_FAILURE',
  failureType: 'testCodeFailure',
  cause: AssertionError [ERR_ASSERTION]: Missing "Article". Found: NotificationProvider, NavBar
      at file:.../utils/__tests__/buildContent.test.mjs:31:7
      at Array.forEach (<anonymous>)
      at TestContext.<anonymous> (file:.../utils/__tests__/buildContent.test.mjs:30:19)
      at async Test.run (node:internal/test_runner/test:1054:7)
      at async Promise.all (index 0)
      at async Suite.run (node:internal/test_runner/test:1442:7)
      at async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3) {
    generatedMessage: false,
    code: 'ERR_ASSERTION',
    actual: false,
    expected: true,
    operator: '=='
  }
}

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@avivkeller avivkeller marked this pull request as ready for review May 28, 2025 22:13
@avivkeller avivkeller requested a review from a team as a code owner May 28, 2025 22:13
@avivkeller avivkeller marked this pull request as draft May 29, 2025 16:36
@avivkeller
Copy link
Member Author

avivkeller commented May 30, 2025

🎉 The code now dehydrates to the client so it can render without JavaScript!

@AugustinMauroy
Copy link
Member

🎉 The code now dehydrates to the client so it run without JavaScript!

Wow 😵‍💫 and what about codetab

@avivkeller
Copy link
Member Author

avivkeller commented May 30, 2025

It rehydrates and runs with JS, but if you don't have JS, you can still view the docs. I used React's SSRing

@avivkeller
Copy link
Member Author

@AugustinMauroy and I got search to finally work 🎉
image

@avivkeller avivkeller force-pushed the feat/web/gen branch 2 times, most recently from 024bbea to dbfe55d Compare June 3, 2025 21:40
@avivkeller
Copy link
Member Author

@nodejs/nodejs-website @nodejs/web-infra ChangeHistory and SideBar aren't implemented yet, so this is still a draft, but it's ready for you to take a look, so feel free to review :-)

@avivkeller avivkeller linked an issue Jun 6, 2025 that may be closed by this pull request
@ovflowd
Copy link
Member

ovflowd commented Jul 9, 2025

@avivkeller I found the issue, the files on .vercelignore get deleted before the build cache gets restored 🤦

@ovflowd
Copy link
Member

ovflowd commented Jul 9, 2025

[12:14:00.889] Running build in Portland, USA (West) – pdx1
[12:14:00.889] Build machine configuration: 4 cores, 8 GB
[12:14:00.906] Cloning github.com/nodejs/api-docs-tooling (Branch: feat/web/gen, Commit: 89b924a)
[12:14:01.526] Cloning completed: 620.000ms
[12:14:01.583] Found .vercelignore
[12:14:01.585] Removed 0 ignored files defined in .vercelignore
[12:14:01.733] Restored build cache from previous deployment (C4uxXMmxowy7HiVuJMfKhbr7PiC1)
[12:14:02.304] Running "vercel build"
[12:14:02.723] Vercel CLI 44.2.13
[12:14:03.292] Running "install" command: `./scripts/vercel-prepare.sh`...
[12:14:03.297] Cloning into 'node'...
[12:14:22.742] Updating files:  26% (11087/41733)
Updating files:  27% (11268/41733)
Updating files:  28% (11686/41733)
Updating files:  29% (12103/41733)
Updating files:  30% (12520/41733)
Updating files:  31% (12938/41733)
Updating files:  32% (13355/41733)
Updating files:  33% (13772/41733)
Updating files:  34% (14190/41733)
Updating files:  35% (14607/41733)
Updating files:  36% (15024/41733)
Updating files:  37% (15442/41733)
Updating files:  38% (15859/41733)
Updating files:  39% (16276/41733)
Updating files:  40% (16694/41733)
Updating files:  41% (17111/41733)
Updating files:  42% (17528/41733)
Updating files:  43% (17946/41733)
Updating files:  44% (18363/41733)
Updating files:  45% (18780/41733)
Updating files:  46% (19198/41733)
Updating files:  47% (19615/41733)
Updating files:  48% (20032/41733)
Updating files:  49% (20450/41733)
Updating files:  50% (20867/41733)
Updating files:  51% (21284/41733)
Updating files:  52% (21702/41733)
Updating files:  53% (22119/41733)
Updating files:  54% (22536/41733)
Updating files:  55% (22954/41733)
Updating files:  56% (23371/41733)
Updating files:  57% (23788/41733)
Updating files:  58% (24206/41733)
Updating files:  59% (24623/41733)
Updating files:  60% (25040/41733)
Updating files:  61% (25458/41733)
Updating files:  62% (25875/41733)
Updating files:  63% (26292/41733)
Updating files:  63% (26462/41733)
Updating files:  64% (26710/41733)
Updating files:  65% (27127/41733)
Updating files:  66% (27544/41733)
Updating files:  67% (27962/41733)
Updating files:  68% (28379/41733)
Updating files:  69% (28796/41733)
Updating files:  70% (29214/41733)
Updating files:  71% (29631/41733)
Updating files:  72% (30048/41733)
Updating files:  73% (30466/41733)
Updating files:  74% (30883/41733)
Updating files:  75% (31300/41733)
Updating files:  76% (31718/41733)
Updating files:  77% (32135/41733)
Updating files:  78% (32552/41733)
Updating files:  79% (32970/41733)
Updating files:  80% (33387/41733)
Updating files:  81% (33804/41733)
Updating files:  82% (34222/41733)
Updating files:  83% (34639/41733)
Updating files:  84% (35056/41733)
Updating files:  85% (35474/41733)
Updating files:  86% (35891/41733)
Updating files:  87% (36308/41733)
Updating files:  88% (36726/41733)
Updating files:  89% (37143/41733)
Updating files:  90% (37560/41733)
Updating files:  91% (37978/41733)
Updating files:  92% (38395/41733)
Updating files:  93% (38812/41733)
Updating files:  94% (39230/41733)
Updating files:  95% (39647/41733)
Updating files:  96% (40064/41733)
Updating files:  97% (40482/41733)
Updating files:  98% (40899/41733)
Updating files:  99% (41316/41733)
Updating files:  99% (41610/41733)
Updating files: 100% (41733/41733)
Updating files: 100% (41733/41733), done.
[12:14:32.004] 
[12:14:32.004] > prepare
[12:14:32.004] > husky
[12:14:32.004] 
[12:14:32.068] 
[12:14:32.069] added 704 packages, and audited 705 packages in 9s
[12:14:32.069] 
[12:14:32.069] 292 packages are looking for funding
[12:14:32.069]   run `npm fund` for details
[12:14:32.071] 
[12:14:32.071] 1 low severity vulnerability
[12:14:32.071] 
[12:14:32.071] To address all issues, run:
[12:14:32.071]   npm audit fix
[12:14:32.071] 
[12:14:32.071] Run `npm audit` for details.
[12:14:32.222] Generating man page (node.1)
[12:14:34.759] Generating addon tests
[12:14:36.785] Generating API doc links
[12:14:40.500] Generating API docs: orama-db, legacy-json, llms-txt, web
[12:16:16.972] Build Completed in /vercel/output [2m]
[12:16:17.005] Deploying outputs...
[12:16:19.467] 
[12:16:19.834] Deployment completed

Takes around 2m to build all these generators on CI. Eventually I'd be good to check:

  • If there are any bottlenecks on legacy-json generator
  • Further reduce web generator bottleneck (on my PC around 63 seconds, so I bet on CI I'd be around 90-120 seconds at least)

@avivkeller
Copy link
Member Author

Rebasing to include #347

@ovflowd
Copy link
Member

ovflowd commented Jul 10, 2025

Using Rolldown appears to reduce compile time significantly... if I can get it to work 😅

What piece is not working? 👀

@avivkeller
Copy link
Member Author

avivkeller commented Jul 10, 2025

What piece is not working? 👀

(Oops, I accidentally deleted the comment)

It's causing a SyntaxError in some of the compiled code, which I'm investigating. It has to do with the string interpolation 🤔

If you look at https://api-docs-tooling-7fvr17mt4-openjs.vercel.app/, it doesn't generate most of the documentation.

@avivkeller
Copy link
Member Author

🤦 I was using Math.random().toString(36).slice(2) to generate unique variable names, but forgot that that doesn't generate safe JavaScript variables (since it can start with a number). I needed to prefix it with _.

@avivkeller
Copy link
Member Author

Based on my estimates, it should decrease the compile time, but we will see.

@ovflowd
Copy link
Member

ovflowd commented Jul 10, 2025

Based on my estimates, it should decrease the compile time, but we will see.

Is the latest version using Rolldown?

@ovflowd
Copy link
Member

ovflowd commented Jul 10, 2025

node bin/cli.mjs generate -t web -i "../node/doc/api/*.md" -o "./out" --index  52.77s user 15.80s system 202% cpu 33.882 total

@ovflowd
Copy link
Member

ovflowd commented Jul 10, 2025

node bin/cli.mjs generate -t web -i "../node/doc/api/*.md" -o "./out" --index  52.77s user 15.80s system 202% cpu 33.882 total

Note that this is around 10s faster than the previous one. Are we still thinking on LightningCSS?

BTW, I still find impressive building all these react pages under 1 minute. They are huge long massive pages.

@avivkeller
Copy link
Member Author

avivkeller commented Jul 10, 2025

Note that this is around 10s faster than the previous one. Are we still thinking on LightningCSS?

The 10s improvement comes from LightningCSS + Rolldown, yes. Based on my testing, Rolldown is slightly faster than ESBuild, the LightningCSS is much faster than PostCSS, hence the improvement.

BTW, I still find impressive building all these react pages under 1 minute. They are huge long massive pages.

🎉 (My goal to make them even faster 🚀)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add react-web generator Write React Components
8 participants