1
0
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:
Phuoc Nguyen
2021-04-18 12:13:41 +07:00
parent 41c59226df
commit f29c093457
3 changed files with 34 additions and 1 deletions

View 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();
})();