123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- const glob = require('glob');
- const puppeteer = require('puppeteer');
- const fs = require('fs');
- const path = require('path');
- async function wait(time) {
- return new Promise(resolve => {
- setTimeout(resolve, time);
- });
- }
- async function snapshot(browser, themePath) {
- let themeName = path.basename(themePath, '.js');
- let code = fs.readFileSync(themePath, 'utf-8');
- let page = await browser.newPage();
- await page.evaluateOnNewDocument(code);
- await page.setViewport({ width: 1200, height: 1200 });
- try {
- await page.goto('http://localhost/echarts/theme/tool/thumb.html#' + themeName);
- await wait(200);
- await page.screenshot({ path: __dirname + '/../thumb/' + themeName + '.png' });
- }
- catch (e) {
- console.log(e);
- }
- await page.close();
- console.log('Updated ' + themeName);
- }
- glob('../*.js', async function (err, themePathList) {
- let browser = await puppeteer.launch();
- for (let themePath of themePathList) {
- try {
- await snapshot(browser, themePath);
- }
- catch(e) {
- console.log(e);
- }
- }
- await browser.close();
- });
|