Skip to content

refactor: split the generator engine into focused modules - #20

Merged
luangjokaj merged 3 commits into
mainfrom
refactor/split-generator-modules
Jul 30, 2026
Merged

refactor: split the generator engine into focused modules#20
luangjokaj merged 3 commits into
mainfrom
refactor/split-generator-modules

Conversation

@luangjokaj

@luangjokaj luangjokaj commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Splits src/mdx-to-nextjs-generator.ts (~2760 lines) into eleven focused modules under src/generator/: secure-source-fs, app-scaffolder, project-config-repository, section-resolver, page-catalog, page-renderer, generated-route-manager, api-reference-generator, public-asset-manager, site-artifacts, and watch-coordinator. The generator file itself becomes a thin orchestrator that wires these modules together.
  • No behavioral changes intended; this is a pure extraction to keep each concern independently readable and testable.
  • Also fixes the Accordion template: drops the redundant cherry Button/resetButton wrapper in favor of a plain styled.button, since StyledAccordionTitle already reimplements a full manual button reset inline.

Test plan

  • pnpm build (tsc compiles clean)
  • pnpm test (228 tests passing across 15 files)
  • pnpm format:check (Prettier clean)

src/mdx-to-nextjs-generator.ts shrinks from ~2760 lines to a thin
orchestrator that wires together eleven new modules under
src/generator/:

- secure-source-fs.ts: SecureSourceFs, a hardened fs layer that scopes
  reads to the documentation root and project root, guarding against
  path traversal and symlink escapes.
- app-scaffolder.ts: AppScaffolder writes the initial Next.js app
  structure (appStructure/obsoleteFiles/startingDocsStructure) plus
  the robots, next.config, pnpm-workspace, and proxy templates.
- project-config-repository.ts: ProjectConfigRepository reads,
  validates, and writes the JSON config files (navigation, sections,
  fonts, analytics) through SecureSourceFs.
- section-resolver.ts: validateSectionsConfig, discoverSections,
  addApiReferenceSection, and determineSectionRoute resolve an MDX
  file's section and slug.
- page-catalog.ts: parseMdxPageMeta, validateRouteCollisions, and
  mergePages build and merge the page-metadata catalog from MDX
  frontmatter.
- page-renderer.ts: renderMdxPage, renderHomepage, and
  renderSectionPage turn parsed MDX into page content and RSS route
  state.
- generated-route-manager.ts: GeneratedRouteManager reconciles routes
  owned by generated MDX pages via the GeneratedArtifacts registry.
- api-reference-generator.ts: ApiReferenceGenerator produces the
  OpenAPI-driven synthetic reference pages and routes.
- public-asset-manager.ts: PublicAssetManager mirrors the public/
  directory and manages the llms.txt/llms-full.txt/skill.md/
  .well-known/mcp.json aggregate files.
- site-artifacts.ts: buildSitemapEntries and related helpers generate
  sitemap.xml, robots.txt, and the llms files from the page catalog.
- watch-coordinator.ts: WatchCoordinator owns the chokidar watchers
  for MDX, config, font, analytics, doccupine.json, public/, and
  OpenAPI spec sources.

No behavioral changes are intended; this is a pure extraction to keep
each concern independently readable and testable.
StyledAccordionTitle already reimplements a full manual button reset
(appearance, border, background, font, cursor) inline, so wrapping
cherry's Button and layering resetButton on top only fought that
styling with Button's own defaults. Switch the styled-component base
to a plain styled.button and drop the now-unused Button/resetButton
import.
@luangjokaj
luangjokaj merged commit f9a43e9 into main Jul 30, 2026
1 check passed
@luangjokaj
luangjokaj deleted the refactor/split-generator-modules branch July 30, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant