From 8242d1d06f1f98e88827812bb8b68550d0dfd3cb Mon Sep 17 00:00:00 2001 From: codecalm Date: Thu, 12 Mar 2020 11:59:18 +0100 Subject: build icons --- gulpfile.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index d985184..6840ffd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,9 +1,42 @@ const gulp = require('gulp'), cp = require('child_process'), - glob = require("glob"), - fs = require("fs"), - path = require("path"); + glob = require('glob'), + fs = require('fs'), + path = require('path'), + p = require('./package.json'), + zip = require('gulp-zip'), + puppeteer = require('puppeteer'); + +const createScreenshot = async (filePath) => { + try { + filePath = path.join(__dirname, filePath); + + const fileName = path.basename(filePath, path.extname(filePath)); + const htmlFilePath = path.join("file:", filePath); + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + + console.log('htmlFilePath', htmlFilePath); + + await page.setViewport({ + height: 100, + width: 100 + }); + + await page.goto(htmlFilePath); + + await page.screenshot({ + path: `${fileName}.png`, + omitBackground: false, + fullPage: true + }); + await browser.close(); + } catch (error) { + console.error(error); + throw Error(error); + } +}; gulp.task('icons-sprite', function (cb) { glob("_site/icons/*.svg", {}, function (er, files) { @@ -74,6 +107,7 @@ gulp.task('icons-preview', function (cb) { const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; fs.writeFileSync('icons.svg', svgContent); + createScreenshot('icons.svg'); cb(); }); }); @@ -110,6 +144,7 @@ gulp.task('icons-stroke', function (cb) { const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; fs.writeFileSync('icons-stroke.svg', svgContent); + createScreenshot('icons-stroke.svg'); cb(); }); @@ -136,11 +171,24 @@ gulp.task('optimize', function (cb) { }); }); -gulp.task('build', function (cb) { +gulp.task('build-zip', function(cb) { + const version = p.version; + + return gulp.src('dist/**/*') + .pipe(zip(`${version}.zip`)) + .pipe(gulp.dest('packages')) +}); + +gulp.task('build-jekyll', function(cb){ cp.exec('bundle exec jekyll build', function() { + cb(); + }); +}); - cp.exec('rm -f ./dist/icons/* && cp ./_site/icons/* ./dist/icons', function() { - cb(); - }); - }) +gulp.task('build-copy', function(cb){ + cp.exec('mkdir -p dist/icons/ && rm -f ./dist/icons/* && cp ./_site/icons/* ./dist/icons && cp ./icons.{png,svg} ./dist && cp ./tabler-icons.png ./dist', function() { + cb(); + }); }); + +gulp.task('build', gulp.series('build-jekyll', 'build-copy', 'build-zip')); -- cgit v1.2.1