mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-30 09:09:50 +02:00
Generate screenshot automatically
This commit is contained in:
29
bin/generateScreenshots.ts
Normal file
29
bin/generateScreenshots.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
import Pattern from '../client/constants/Pattern';
|
||||
import slug from '../client/helpers/slug';
|
||||
|
||||
process.setMaxListeners(0);
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch();
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(Pattern).map(async ([_, patternName]) => {
|
||||
const page = await browser.newPage();
|
||||
const pattern = slug(patternName);
|
||||
await page.goto(`http://localhost:1234/patterns/${pattern}`);
|
||||
|
||||
await page.waitForSelector('.demo');
|
||||
const element = await page.$('.demo');
|
||||
await element.screenshot({
|
||||
path: `public/patterns/${pattern}.png`
|
||||
});
|
||||
await page.close();
|
||||
})
|
||||
);
|
||||
|
||||
await browser.close();
|
||||
})();
|
Reference in New Issue
Block a user