aboutsummaryrefslogtreecommitdiff
path: root/gulpfile.js
diff options
context:
space:
mode:
authorcodecalm <codecalm@gmail.com>2020-03-16 21:32:48 +0100
committercodecalm <codecalm@gmail.com>2020-03-16 21:32:48 +0100
commit8dd3f0b19473b4365373855c064e7fa5b0e8d351 (patch)
tree63671de9cc47ac3726a9388f418f5491a71c626e /gulpfile.js
parentreadme fix (diff)
downloadtabler-icons-8dd3f0b19473b4365373855c064e7fa5b0e8d351.tar.xz
png icons
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/gulpfile.js b/gulpfile.js
index 1c562b1..d69d743 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'));