Docs: Add codemod script for docs snippets#30315
Conversation
There was a problem hiding this comment.
3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
| const newSnippet = { ...snippet }; | ||
| newSnippet.attributes.tabTitle = 'CSF 4 (experimental)'; |
There was a problem hiding this comment.
style: redundant assignment of tabTitle - it's set again in the attributes spread below
| export function parseAttributes(attributes: string): Record<string, string> { | ||
| const attributeRegex = /([a-zA-Z0-9.-]+)="([^"]+)"/g; | ||
| const result: Record<string, string> = {}; |
There was a problem hiding this comment.
logic: attributeRegex is too permissive - should escape dots and validate attribute names more strictly
| program | ||
| .name('command') | ||
| .description('A minimal CLI for demonstration') |
There was a problem hiding this comment.
style: CLI name and description are placeholder values that should be updated with actual command details
|
View your CI Pipeline Execution ↗ for commit 3fad32c.
☁️ Nx Cloud last updated this comment at |
831bf94 to
7d38d73
Compare
f75b007 to
80c80ac
Compare
7d38d73 to
a7bbc4c
Compare
3638e44 to
b95322e
Compare
|
@vanessayuenn @kylegach @jonniebigodes I'm turning this PR into draft but it would be lovely to know what the plans are for the CSF factories docs |
|
Closing this, if we ever need it we can bring this back. cc @kylegach @jonniebigodes |
Closes #30383
What I did
This PR adds a new command to the scripts directory to be able to run codemods in our own documentation file.
Based on a specified codemod and glob, it will essentially go through all of the files, extract all snippets from that given file, go through some logic to define which target snippets should be migrated, then apply the codemod to those snippets.
You can run it like so in the scripts directory:
for instance:
available codemods:
csf-factory-story (for stories snippets), csf-factory-config (for preview.js/main.js snippets)
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>Greptile Summary
Adds a new codemod script for transforming documentation code snippets to CSF 4 format, with functionality to extract, transform, and append updated snippets while maintaining original content.
scripts/snippets/codemod.tswith snippet extraction and transformation logic using concurrent processingSNIPPETS_DIRECTORYconstant inscripts/utils/constants.tspointing to '_snippets' directorydocs:codemodscript command andglobbydependency inscripts/package.json