Update script to support current tailwindui.com#11
Open
wzulfikar wants to merge 12 commits intopointblankdev:mainfrom
Open
Update script to support current tailwindui.com#11wzulfikar wants to merge 12 commits intopointblankdev:mainfrom
wzulfikar wants to merge 12 commits intopointblankdev:mainfrom
Conversation
wzulfikar
commented
Nov 1, 2022
| @@ -0,0 +1,10 @@ | |||
| const fs = require("fs"); | |||
|
|
|||
| function writeToFile(outputDir, componentType, sections, error = false) { | |||
This was referenced Nov 2, 2022
wzulfikar
commented
Nov 2, 2022
| @@ -0,0 +1,12 @@ | |||
| [ | |||
Contributor
Author
There was a problem hiding this comment.
Sample output of getSections.js (added here for reference)
wzulfikar
commented
Nov 2, 2022
Comment on lines
+20
to
+22
| if (!toggleCode) { | ||
| return | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Allow the script to keep going when the code block is locked (user has no access to it).
Example component ("Get the code" indicates the code block is locked):
This was referenced Nov 2, 2022
wzulfikar
commented
Nov 2, 2022
| // Change the type of code snippet to HTML/React/Vue (hint: ../docs/hints/toggle-code-format.png) | ||
| const toggleSnippetType = el.querySelector('select.form-select') | ||
| toggleSnippetType.value = type; | ||
| toggleSnippetType.dispatchEvent(new Event('change', { bubbles: true })); |
Contributor
Author
There was a problem hiding this comment.
bubbles: true is needed otherwise the onChange event won't be propagated to React and it won't rerender (SO).
wzulfikar
commented
Nov 2, 2022
| const componentName = pascalCase(component.title); | ||
|
|
||
| // Add `Component_` prefix for import name if component name starts with number | ||
| const importName = componentName.match(/^\d/) ? `Component_${componentName}` : componentName; |
Contributor
Author
|
@wzulfikar This is cool! Worked for me. |
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.



What
Update scraper to make it work for the new tailwindui.com site. This PR also tries to improve the codebase so it's easier to maintain.
Checklist:
.env.sampleas a template for environment variables required by the scriptyarn start react,yarn create-mdx react)Why
The previous code no longer work due to changes in tailwindui.com.
Test plan
yarn start reactand it should create a json file at./output/tailwindui.react.jsonyarn create-mdx reactand it should create the Storybook stories at./output/tailwindui-react/Preview:
twui-storybook.mp4.mp4
I also tested the generated code in Stackblitz to ensure that it works with current latest Storybook. Screenshot: