Skip to content

cli(feat): scaffold file-only article components and keep README rows in the table - #614

Merged
Ducksss merged 1 commit into
mainfrom
claude/scaffolder-file-only
Oct 10, 2026
Merged

Ducksss merged 1 commit into
mainfrom
claude/scaffolder-file-only

Conversation

@Ducksss

@Ducksss Ducksss commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Summary

This fixes the two pnpm payload-components new gaps found while building related-posts (#600):

  1. new only scaffolded Pages blocks. It now takes --file-only for file-only article components, the shape post-hero, author-card, newsletter-callout, and related-posts ship. Before this, related-posts had to be mirrored by hand: running new related-posts produced source/blocks/RelatedPosts/config.ts, Pages fragments, and generate:* tasks.
  2. The README inventory row landed outside the table. It was inserted after the blank line that separates the table from <!-- COMPONENT-INVENTORY:END -->. It is now the table's last row, for both paths.

The option name matches the manifest's installMode: 'file-only', which is the term add, localize, seed, and remove already use for these components. contributor-cli.ts accepts exactly one slug plus this flag and refuses any other option by name.

What --file-only writes

Output Path / content
Source payload-components/source/components/<Pascal>/Component.tsx: public React props (title, description) plus id, className, disableInnerContainer. It imports only React, in the article-component style (no cn, no @/ imports).
Manifest installMode: 'file-only', empty payloadFragments, postInstall, and recovery.patchedFiles. supports, supportedTargets, and the payload / next peer ranges are derived from support-matrix.json, not hardcoded. react: ^19.0.0 stays a constant because React isn't in the matrix.
Registry item registry:component, one file targeting ~/src/components/<Pascal>/Component.tsx, requiresPayloadComponentWrapper: false, postInstall: [], registryDependencies: [].
Catalog The generated projection (src/generated/component-catalog.json) and the Components.<slug> label in messages/en.json; an existing label, such as one from a former upcoming entry, is kept. The Posts entry in componentEditorialEntries is written when a word of the slug names an existing Posts category.
Docs content/docs/components/<slug>.mdx in the file-only format: Preview, Command/Manual tabs, ComponentWiring, a TypeTable, then ComponentUsage with a minimal React usage example and no Pages-block steps, then ComponentRequirements. Also the sidebar meta.json entry.
Demo twin src/components/site/demos/<Pascal>Demo.tsx mirrors every class group of the scaffolded component, plus its demosBySlug entry. Every surface that renders demosBySlug (the preview route, docs, catalog thumbs, wall, teaser) wraps twins in .preview-scope (tests/int/brand-layer.int.spec.ts), so registering it is what places it there, like every other twin.
README The inventory row, inside the table.

The source, twin, and doc page come from new templates in payload-components/component-template/file-only/, next to the block templates; tsc and eslint already exclude that directory.

Support derivation

Payload and Next.js majors are the union of every target's allowed majors. Each peer range admits each major's stable line, and the newest Payload major also admits prereleases (^N.0.0-0), which is the rule payload-components-support-matrix.int.spec.ts enforces. With today's matrix this reproduces the shipped values exactly: [3, 4], [15, 16], ^3.0.0 || ^4.0.0-0, ^15.0.0 || ^16.0.0. A test adds Payload 5 to a scratch matrix and checks that the scaffold follows (^3.0.0 || ^4.0.0 || ^5.0.0-0).

What it prints instead of guessing

Sample output for pnpm payload-components new author-bio --file-only:

payload-components: scaffolded "author-bio" as a file-only article component.

Created:
  payload-components/source/components/AuthorBio/Component.tsx
  payload-components/manifests/author-bio.json
  content/docs/components/author-bio.mdx
  src/components/site/demos/AuthorBioDemo.tsx

Appended:
  payload-components/registry.json
  src/components/site/demos/registry.ts
  content/docs/components/meta.json
  README.md
  messages/en.json
  src/lib/component-catalog.ts

Generated:
  src/generated/component-catalog.json

Now the parts that need a decision — none of these were written for you:

1. src/lib/component-catalog.ts → the Posts entry for author-bio uses category
   'author', matched from the slug. Confirm it, or move it to another Posts
   category (cards, archive, header, index, author, newsletter, related).
   A new Posts category also needs componentCategories and a CatalogBrowser.categories
   label in every draft locale (tests/int/crowdin-sync.int.spec.ts).

2. messages/en.json → Components.author-bio: replace the TODO description and target.
   zh has no English fallback (src/i18n/catalog-policy.ts), so
   messages/locales/zh.json needs Components.author-bio translated through Crowdin or
   a native reviewer; tests/int/crowdin-sync.int.spec.ts fails until it is.

3. payload-components/source/components/AuthorBio/Component.tsx → the real props and
   markup. Keep src/components/site/demos/AuthorBioDemo.tsx mirroring every class group.

4. Fill every TODO in the manifest, the registry item, and the doc page: description,
   preview.summary, sampleContent, the Content model TypeTable, the usage example, and
   where the component goes in the post template.

5. tests/int/article-components.int.spec.tsx → add it to the React typecheck list and the
   direct shadcn delivery and lifecycle it.each, and add a render test. Update the literal
   catalog counts in tests/int/fumadocs-site.int.spec.ts and the Posts list in
   tests/int/site-catalog.int.spec.ts.

6. Visual baselines cannot be generated here — dispatch the visual-baselines workflow
   for components-visual, and for frontend too if the footer gains a category link.

Then, once the source is final: pnpm registry:snapshot && pnpm registry:build &&
pnpm test:registry && pnpm run test:int

When no word of the slug names a Posts category (for example reading-time), the entry is printed with category: 'TODO' instead of written. A new Posts category needs a CatalogBrowser.categories key in every draft locale, which the Crowdin gate blocks, so the scaffold never invents one.

Why zh is a printed step. I found this by running the scaffold in a real checkout. allowsCatalogFallback exempts zh from the Components.* English fallback. The existing article components only passed because their zh labels date from their "upcoming" days. The scaffold won't write English into zh.json as a stand-in translation, since that is exactly what the gate exists to stop.

Trial in a real checkout. I scaffolded author-bio --file-only into this repo, ran the real gates, then reverted. tsc, lint, format:check, i18n:check, and test:registry all passed, as did the demo-twin, visual-standards, public-registry, inventory-sync, support-matrix, brand-layer, and fresh-smoke specs. The only failures were the hand-maintained items the output lists: the two literal catalog-count pins, the Posts list in site-catalog.int, and the zh label.

The Pages-block path is unchanged

I put origin/main's new.ts beside this branch's in a throwaway spec and scaffolded parity-probe-block with each into identical scratch roots built from the real registry, manifests, docs meta, demo registry, catalog, en.json, and README.

  • The printed output is identical, and so is the set of files written.
  • Every file is byte-identical except README.md, where the only difference is the row's position: after the blank line on main, inside the table here.

The spec and the module were deleted afterwards. In the code, the block path changed in three places: an optional item parameter on prepareRegistryItem that defaults to the old builder, the shared README insertion, and the fileOnly dispatch in newCommand. A permanent test now pins the block scaffold to the block templates byte for byte (config.ts, Component.tsx, doc-page.mdx, and buildManifest) and asserts it never touches en.json, component-catalog.ts, or source/components/.

A spec isolation bug, fixed

While mutation-checking, a filtered run (vitest -t "README inventory row") scaffolded aa-scaffold-probe into the real checkout. The spec statically imports commands/new, which binds it to the real repoRoot. Each test then mocks repoRoot and re-imports the module, but that only yields a fresh module after vi.resetModules(). The first scaffold test had been relying on an earlier test's afterEach reset, and -t skips that test.

I removed the stray files (everything I created) and added a beforeEach(vi.resetModules). The same filtered mutation run now fails the three README tests and leaves the tree clean.

Tests

tests/int/payload-components-new-command.int.spec.ts, 11 new cases:

  • README row. It is the table's last row, immediately after the previous last row, with the end marker after the blank line. A second case checks it is padded to the existing column widths.
  • Block path. Byte-identical to the block templates and buildManifest, and the file-only targets are untouched.
  • --file-only files and loader. It writes the right files, and the real loadManifest (schema plus contract validation) accepts the manifest.
  • Support derivation. Support follows the support matrix, including a matrix with an added Payload 5.
  • Projections and formatting. Registry, demo registry, docs meta, README, generated catalog, en.json label, and the Posts entry are all appended. The doc page has exactly the five file-only sections and a React usage example. The twin carries every class group of the component. component-catalog.ts, en.json, the twin, and the demo registry pass prettier.check.
  • No matching category. The entry is printed, and component-catalog.ts is unchanged.
  • Existing label. It is kept, and the doc page takes its title.
  • CLI flags. --file-only is accepted; --file and a missing slug are refused before anything is written.

tests/int/payload-components-support-matrix.int.spec.ts gains "manifests written by new --file-only agree with the support matrix".

Mutation check: restoring the old insertion point (end instead of the table's last row) fails three tests, the two README cases and the file-only projection case.

Verification (local; exit codes captured to files)

Gate Exit Result
pnpm source:build 0
pnpm lint 0
pnpm format:check 0
pnpm exec tsc --noEmit 0
pnpm test:registry 0 83 source items + built public/r artifacts valid
pnpm run test:int 0 66 files passed, 1 skipped; 834 tests passed, 1 skipped (116s, load average ~28, no timeouts)

This is repository-only contributor tooling: nothing ships in the npm package (component-template/ isn't in files), and no site page changes. So per the brief I didn't run build:e2e or production e2e; CI covers them.

Docs

The AGENTS.md "Add a component" row documents --file-only; Prettier re-pads that table because the row is its widest cell. Also updated: CONTRIBUTING.md, content/docs/cli.mdx ("Contribute a component"), and payload-components/component-template/README.md ("Expected Files").

Left over

  • Stale block-path text. The block path still hardcodes its support values (they match the matrix today) and still prints the stale darwin visual-baseline step and the old literal-string componentEditorialEntries snippet. I left all of it untouched to keep that path byte-identical; it could adopt deriveSupport and the englishMessages entry shape in a follow-up.
  • README column width. README rows still don't widen the table when a new slug is longer than the current column (padEnd doesn't truncate). That's pre-existing, and Prettier would then re-pad the table.

🤖 Generated with Claude Code

… in the table

`pnpm payload-components new <slug> --file-only` scaffolds a file-only
article component, like post-hero or related-posts, instead of a Pages
block. It writes:

- payload-components/source/components/<Pascal>/Component.tsx with public
  React props plus id, className and disableInnerContainer
- an installMode 'file-only' manifest with empty fragments, post-install
  tasks and recovery paths; supports and peer ranges are derived from
  support-matrix.json
- a registry:component item targeting ~/src/components/
- the generated catalog projection and the Components.<slug> label in
  messages/en.json
- the Posts catalog entry, when a word of the slug names an existing
  Posts category
- the file-only doc page with a React usage example, the demo twin and its
  registry entry, the docs sidebar entry, and the README inventory row

It prints the decisions it won't guess: the category, the catalog copy,
the zh translation (zh has no English fallback), and the hand-maintained
test lists. The Pages-block path writes byte-identical files apart from
the README fix below.

The README inventory row was inserted after the blank line that closes the
table, so markdown read it outside the table. It now lands directly after
the table's last row, for both paths.

The new-command spec now resets modules before every test. Each scaffold
test depended on an earlier test's afterEach reset to get a mocked
repoRoot. A filtered run (-t) therefore scaffolded into the real checkout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 19:14
@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
payload-components Ready Ready Preview Oct 9, 2026 7:16pm UTC
payload-components-97bf Ready Ready Preview Oct 9, 2026 7:16pm UTC

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 36 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: Ducksss/payload-components/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d3b79626-d8d0-4ade-ba59-265d7c9260f6

📥 Commits

Reviewing files that changed from the base of the PR and between 05c931d and 0a4e39f.


📒 Files selected for processing (11)
  • AGENTS.md
  • CONTRIBUTING.md
  • content/docs/cli.mdx
  • payload-components/component-template/README.md
  • payload-components/component-template/file-only/Component.tsx
  • payload-components/component-template/file-only/Demo.tsx
  • payload-components/component-template/file-only/doc-page.mdx
  • tests/int/payload-components-new-command.int.spec.ts
  • tests/int/payload-components-support-matrix.int.spec.ts
  • tools/payload-components/commands/new.ts
  • tools/payload-components/contributor-cli.ts


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Ducksss
Ducksss merged commit fe8e295 into main Oct 10, 2026
18 checks passed
@Ducksss
Ducksss deleted the claude/scaffolder-file-only branch October 10, 2026 03:48
@Ducksss Ducksss mentioned this pull request Oct 29, 2026

This branch was successfully deployed

2 active deployments
Preview – payload-components — 0a4e39f4 Deployed Oct 9, 2026 by vercel[bot]
Preview – payload-components-97bf — 0a4e39f4 Deployed Oct 9, 2026 by vercel[bot]
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.

2 participants