-
Notifications
You must be signed in to change notification settings - Fork 18
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
Update script to support current tailwindui.com #11
Open
wzulfikar
wants to merge
12
commits into
pointblankdev:main
Choose a base branch
from
wzulfikar:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
59a6e40
Login works. Parse sections work.
wzulfikar f9a0fe2
Extract codes to lib and util
wzulfikar da38fd9
Parsing works
wzulfikar 5425ca8
Fix react to storybook
wzulfikar 176604c
f
wzulfikar b1314c6
Add json sample
wzulfikar ab826b7
f
wzulfikar 8f194ef
f
wzulfikar c2778be
Add guest mode
wzulfikar 1131394
Add `Component_` prefix for import name if component name starts with…
wzulfikar c4598ee
Format template
wzulfikar da03a54
f
wzulfikar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BASE_URL=https://tailwindui.com | ||
|
||
email=some-email | ||
password=some-password | ||
slowmo=0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,10 @@ The two steps process makes it easy to adjust for future needs. | |
|
||
```sh | ||
# Format: | ||
email=<[email protected]> password=<yourpassword> node tailwindui.js <react|vue|html> | ||
yarn start <react|vue|html> | ||
|
||
# Example: | ||
email='[email protected]' password='pass123' node tailwindui.js react | ||
yarn start react | ||
``` | ||
|
||
The command will start chromium and navigate thru tailwindui.com website to copy the components codes. Here's how it looks like: | ||
|
@@ -40,8 +40,8 @@ The two steps process makes it easy to adjust for future needs. | |
5. Now we can create the mdx files based on above json. To do so, run: | ||
|
||
```sh | ||
# Replace `react.json` suffix with `vue.json` as you fit | ||
node tailwindui-storybook.js ./output/tailwindui.react.json react | ||
# Replace "react" with "html" or "vue" (based on step 3) | ||
yarn create-mdx react | ||
``` | ||
|
||
![tailwindui-storybook](docs/tailwindui-storybook-mdx.gif) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const baseUrl = process.env.BASE_URL; | ||
|
||
async function getComponents(page, sectionUrl, type = "html") { | ||
// Go to section url. Example: https://tailwindui.com/components/marketing/sections/heroes | ||
await page.goto(sectionUrl); | ||
|
||
const toggleCodeSelector = '[role=tablist] > [id^=headlessui-tabs-tab-]:nth-child(2)' | ||
try { | ||
// Element to toggle code snippet (hint: ../docs/hints/toggle-code.png). | ||
// The element won't exist if the user doesn't have access to the paid component. | ||
await page.waitForSelector(toggleCodeSelector, { timeout: 10 * 1000 }); | ||
} catch (error) { | ||
console.warn(`You do not have access this section components: ${sectionUrl}`); | ||
} | ||
|
||
const components = await page.evaluate(([toggleCodeSelector, type]) => { | ||
let components = []; | ||
document.querySelectorAll('section[id^="component-"]').forEach((el) => { | ||
// Toggle code block | ||
el.querySelector(toggleCodeSelector)?.click(); | ||
|
||
// 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 })); | ||
|
||
// Extract code blocks (hint: ../docs/hints/codeblock.png) | ||
const title = el.querySelector("h2 a").innerText; | ||
const codeblock = el.querySelector('pre code')?.innerText; | ||
codeblock && components.push({ title, codeblocks: { [type]: codeblock } }); | ||
}); | ||
return Promise.resolve(components); | ||
}, [toggleCodeSelector, type]); | ||
|
||
// Back to home page | ||
await page.goto(baseUrl); | ||
|
||
return components; | ||
} | ||
|
||
module.exports = getComponents |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
async function getSections(page) { | ||
const sections = await page.evaluate(([]) => { | ||
const buildSections = []; | ||
document | ||
.querySelectorAll('a[href^="/components"]') | ||
.forEach((el) => { | ||
const title = el.children[1]?.innerText; | ||
const countComponents = el.parentElement?.nextElementSibling?.innerText; | ||
const url = el.href; | ||
title && countComponents && buildSections.push({ title, componentsCount: parseInt(countComponents), url }); | ||
}); | ||
return Promise.resolve(buildSections); | ||
}, []); | ||
|
||
return sections; | ||
} | ||
|
||
module.exports = getSections |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const baseUrl = process.env.BASE_URL; | ||
const selector = { | ||
email: 'input#email', | ||
password: 'input#password', | ||
submit: 'button[type=submit]', | ||
} | ||
|
||
async function login(page, email, password) { | ||
await page.goto(baseUrl + "/login"); | ||
await page.locator(selector.email).fill(email); | ||
await page.locator(selector.password).fill(password); | ||
await page.locator(selector.submit).click(); | ||
|
||
// Assert login succeeded | ||
const loginFailedToken = "These credentials do not match our records"; | ||
const el = await page.$$(`:text("${loginFailedToken}")`); | ||
if (el.length) { | ||
throw new Error("invalid credentials"); | ||
} | ||
} | ||
|
||
module.exports = login |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
{ | ||
"name": "tailwindui-storybook", | ||
"engine": ">=14", | ||
"scripts": { | ||
"start": "node -r dotenv/config tailwindui.js", | ||
"create-mdx": "node -r dotenv/config tailwindui-storybook.js" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^16.0.3", | ||
"lodash": "^4.17.21", | ||
"playwright": "^1.9.2" | ||
"playwright": "^1.27.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^4.3.3" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.
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.
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.
bubbles: true
is needed otherwise the onChange event won't be propagated to React and it won't rerender (SO).