diff options
author | codecalm <codecalm@gmail.com> | 2020-03-16 21:32:48 +0100 |
---|---|---|
committer | codecalm <codecalm@gmail.com> | 2020-03-16 21:32:48 +0100 |
commit | 8dd3f0b19473b4365373855c064e7fa5b0e8d351 (patch) | |
tree | 63671de9cc47ac3726a9388f418f5491a71c626e /gulpfile.js | |
parent | readme fix (diff) | |
download | tabler-icons-8dd3f0b19473b4365373855c064e7fa5b0e8d351.tar.xz |
png icons
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/gulpfile.js b/gulpfile.js index 1c562b14..d69d7439 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,6 +7,38 @@ const gulp = require('gulp'), zip = require('gulp-zip'), puppeteer = require('puppeteer'); +async function asyncForEach(array, callback) { + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); + } +} + +const svgToPng = async (filePath, destination) => { + filePath = path.join(__dirname, filePath); + + const htmlFilePath = path.join("file:", filePath); + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + + await page.setViewport({ + height: 24, + width: 24, + deviceScaleFactor: 10 + }); + + await page.goto(htmlFilePath); + + await page.screenshot({ + path: path.join(__dirname, destination), + omitBackground: true, + fullPage: true + }); + + await browser.close(); + + return page; +}; + const createScreenshot = async (filePath) => { try { filePath = path.join(__dirname, filePath); @@ -189,4 +221,18 @@ gulp.task('build-copy', function(cb){ }); }); +gulp.task('svg-to-png', gulp.series('build-jekyll', async (cb) => { + let files = glob.sync("_site/icons/*.svg"); + + await asyncForEach(files, async function (file, i) { + let name = path.basename(file, '.svg'); + + console.log('name', name); + + await svgToPng(file, `icons-png/${name}.png`); + }); + + cb(); +})); + gulp.task('build', gulp.series('build-jekyll', 'build-copy', 'build-zip')); |