-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Docs: Add codemod script for docs snippets #30315
base: kasper/csf-factories
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
scripts/snippets/codemod.ts
Outdated
const newSnippet = { ...snippet }; | ||
newSnippet.attributes.tabTitle = 'CSF 4 (experimental)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: CLI name and description are placeholder values that should be updated with actual command details
View your CI Pipeline Execution ↗ for commit a7bbc4c.
☁️ Nx Cloud last updated this comment at |
831bf94
to
7d38d73
Compare
f75b007
to
80c80ac
Compare
7d38d73
to
a7bbc4c
Compare
Closes #
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:merged
orci:daily
GH 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.ts
Make 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/core
team 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.ts
with snippet extraction and transformation logic using concurrent processingSNIPPETS_DIRECTORY
constant inscripts/utils/constants.ts
pointing to '_snippets' directorydocs:codemod
script command andglobby
dependency inscripts/package.json