File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 24
24
"build:react" : " npm run build -w lib && npm run build -w dev/react-project" ,
25
25
"analyze" : " ANALYZE=true npm run build:next" ,
26
26
"screenshots" : " npm run screenshots -w scripts" ,
27
+ "preview" : " npm run preview -w scripts" ,
27
28
"pretty" : " pretty-quick --staged" ,
28
29
"test:e2e" : " npm run test:e2e:next && npm run test:e2e:react" ,
29
30
"test:e2e:next" : " npm run test:e2e:dev:next && npm run test:e2e:build:next" ,
Original file line number Diff line number Diff line change 3
3
"version" : " 1.0.0" ,
4
4
"description" : " " ,
5
5
"scripts" : {
6
- "screenshots" : " node ./screenshots.js"
6
+ "screenshots" : " node ./screenshots.js" ,
7
+ "preview" : " node ./preview.js"
7
8
},
8
9
"author" : " " ,
9
10
"license" : " ISC" ,
Original file line number Diff line number Diff line change
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
+ } ) ( )
You can’t perform that action at this time.
0 commit comments