Skip to content

Commit 4f0c8d0

Browse files
committed
added preview script
1 parent 5276c75 commit 4f0c8d0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"build:react": "npm run build -w lib && npm run build -w dev/react-project",
2525
"analyze": "ANALYZE=true npm run build:next",
2626
"screenshots": "npm run screenshots -w scripts",
27+
"preview": "npm run preview -w scripts",
2728
"pretty": "pretty-quick --staged",
2829
"test:e2e": "npm run test:e2e:next && npm run test:e2e:react",
2930
"test:e2e:next": "npm run test:e2e:dev:next && npm run test:e2e:build:next",

scripts/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "1.0.0",
44
"description": "",
55
"scripts": {
6-
"screenshots": "node ./screenshots.js"
6+
"screenshots": "node ./screenshots.js",
7+
"preview": "node ./preview.js"
78
},
89
"author": "",
910
"license": "ISC",

scripts/preview.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const puppeteer = require('puppeteer')
2+
const fs = require('fs/promises')
3+
const process = require('process')
4+
5+
const tailwindUrl = 'https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css'
6+
7+
const componentsPath = process.cwd() + '/../lib/themes'
8+
const themeName = process.argv[2]
9+
if (!themeName) throw new Error('No theme name')
10+
11+
const componentName = process.argv[3]
12+
if (!componentName)
13+
throw new Error('No component name')
14+
15+
// npm run preview -- hyperui Banner1
16+
;(async () => {
17+
// create page
18+
const browser = await puppeteer.launch({ headless: false })
19+
const page = await browser.newPage()
20+
21+
// render html
22+
const source = await fs.readFile(
23+
`${componentsPath}/${themeName}/${componentName}/index.html`,
24+
'utf8',
25+
)
26+
const html = `<html><head><link rel="stylesheet" href="${tailwindUrl}"></head><body>${source.replaceAll(
27+
'`',
28+
'',
29+
)}</body></html>`
30+
await page.setContent(html)
31+
32+
// wait for a long time
33+
await new Promise((r) => setTimeout(r, 50000))
34+
35+
// close page
36+
await browser.close()
37+
})()

0 commit comments

Comments
 (0)