Repository navigation
cli(feat): scaffold file-only article components and keep README rows in the table - #614
Merged
Merged
Conversation
… 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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou'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. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (11)
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. Comment |
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes the two
pnpm payload-components newgaps found while buildingrelated-posts(#600):newonly scaffolded Pages blocks. It now takes--file-onlyfor file-only article components, the shapepost-hero,author-card,newsletter-callout, andrelated-postsship. Before this,related-postshad to be mirrored by hand: runningnew related-postsproducedsource/blocks/RelatedPosts/config.ts, Pages fragments, andgenerate:*tasks.<!-- 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 termadd,localize,seed, andremovealready use for these components.contributor-cli.tsaccepts exactly one slug plus this flag and refuses any other option by name.What
--file-onlywritespayload-components/source/components/<Pascal>/Component.tsx: public React props (title,description) plusid,className,disableInnerContainer. It imports only React, in the article-component style (nocn, no@/imports).installMode: 'file-only', emptypayloadFragments,postInstall, andrecovery.patchedFiles.supports,supportedTargets, and thepayload/nextpeer ranges are derived fromsupport-matrix.json, not hardcoded.react: ^19.0.0stays a constant because React isn't in the matrix.registry:component, one file targeting~/src/components/<Pascal>/Component.tsx,requiresPayloadComponentWrapper: false,postInstall: [],registryDependencies: [].src/generated/component-catalog.json) and theComponents.<slug>label inmessages/en.json; an existing label, such as one from a former upcoming entry, is kept. The Posts entry incomponentEditorialEntriesis written when a word of the slug names an existing Posts category.content/docs/components/<slug>.mdxin the file-only format: Preview, Command/Manual tabs,ComponentWiring, a TypeTable, thenComponentUsagewith a minimal React usage example and no Pages-block steps, thenComponentRequirements. Also the sidebarmeta.jsonentry.src/components/site/demos/<Pascal>Demo.tsxmirrors every class group of the scaffolded component, plus itsdemosBySlugentry. Every surface that rendersdemosBySlug(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.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 rulepayload-components-support-matrix.int.spec.tsenforces. 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:When no word of the slug names a Posts category (for example
reading-time), the entry is printed withcategory: 'TODO'instead of written. A new Posts category needs aCatalogBrowser.categorieskey in every draft locale, which the Crowdin gate blocks, so the scaffold never invents one.Why
zhis a printed step. I found this by running the scaffold in a real checkout.allowsCatalogFallbackexemptszhfrom theComponents.*English fallback. The existing article components only passed because theirzhlabels date from their "upcoming" days. The scaffold won't write English intozh.jsonas a stand-in translation, since that is exactly what the gate exists to stop.Trial in a real checkout. I scaffolded
author-bio --file-onlyinto this repo, ran the real gates, then reverted.tsc,lint,format:check,i18n:check, andtest:registryall 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 insite-catalog.int, and thezhlabel.The Pages-block path is unchanged
I put
origin/main'snew.tsbeside this branch's in a throwaway spec and scaffoldedparity-probe-blockwith each into identical scratch roots built from the real registry, manifests, docs meta, demo registry, catalog,en.json, and README.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
itemparameter onprepareRegistryItemthat defaults to the old builder, the shared README insertion, and thefileOnlydispatch innewCommand. A permanent test now pins the block scaffold to the block templates byte for byte (config.ts,Component.tsx,doc-page.mdx, andbuildManifest) and asserts it never touchesen.json,component-catalog.ts, orsource/components/.A spec isolation bug, fixed
While mutation-checking, a filtered run (
vitest -t "README inventory row") scaffoldedaa-scaffold-probeinto the real checkout. The spec statically importscommands/new, which binds it to the realrepoRoot. Each test then mocksrepoRootand re-imports the module, but that only yields a fresh module aftervi.resetModules(). The first scaffold test had been relying on an earlier test'safterEachreset, and-tskips 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:buildManifest, and the file-only targets are untouched.--file-onlyfiles and loader. It writes the right files, and the realloadManifest(schema plus contract validation) accepts the manifest.en.jsonlabel, 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 passprettier.check.component-catalog.tsis unchanged.--file-onlyis accepted;--fileand a missing slug are refused before anything is written.tests/int/payload-components-support-matrix.int.spec.tsgains "manifests written bynew --file-onlyagree with the support matrix".Mutation check: restoring the old insertion point (
endinstead 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)
pnpm source:buildpnpm lintpnpm format:checkpnpm exec tsc --noEmitpnpm test:registrypublic/rartifacts validpnpm run test:intThis is repository-only contributor tooling: nothing ships in the npm package (
component-template/isn't infiles), and no site page changes. So per the brief I didn't runbuild:e2eor 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"), andpayload-components/component-template/README.md("Expected Files").Left over
componentEditorialEntriessnippet. I left all of it untouched to keep that path byte-identical; it could adoptderiveSupportand theenglishMessagesentry shape in a follow-up.padEnddoesn't truncate). That's pre-existing, and Prettier would then re-pad the table.🤖 Generated with Claude Code