1
0
mirror of https://github.com/phuoc-ng/csslayout.git synced 2025-10-23 18:56:29 +02:00

Update screenshot script

This commit is contained in:
Phuoc Nguyen
2021-05-09 16:54:21 +07:00
parent 57a1f406c1
commit aadb9fccb0
3 changed files with 35 additions and 30 deletions

34
bin/generateScreenshot.ts Normal file
View File

@@ -0,0 +1,34 @@
#!/usr/bin/env node
// Run this script from the root folder
// $ npm run screenshot slug-of-pattern-here
const puppeteer = require('puppeteer');
const main = () => {
const args = process.argv;
if (!args || !Array.isArray(args) || args.length < 2) {
console.log('Please specific the pattern: npm run screenshot slug-of-pattern-here');
return;
}
const pattern = args[2];
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`http://localhost:1234/patterns/${pattern}`);
await page.waitForSelector('.demo__live');
const element = await page.$('.demo__live');
await element.screenshot({
path: `public/assets/patterns/${pattern}.png`
});
await page.close();
await browser.close();
})();
};
main();