From 5fb2a9255c394d62b59f167dc922c5a05d5bd411 Mon Sep 17 00:00:00 2001 From: codecalm Date: Sun, 22 Mar 2020 13:01:56 +0100 Subject: new releases flow --- gulpfile.js | 147 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 79 insertions(+), 68 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 75699b1..cb820ad 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,8 @@ const gulp = require('gulp'), path = require('path'), p = require('./package.json'), zip = require('gulp-zip'), - puppeteer = require('puppeteer'); + puppeteer = require('puppeteer'), + argv = require('minimist')(process.argv.slice(2)); async function asyncForEach(array, callback) { for (let index = 0; index < array.length; index++) { @@ -47,7 +48,7 @@ const createScreenshot = async (filePath) => { const htmlFilePath = path.join("file:", filePath); const browser = await puppeteer.launch(); const page = await browser.newPage(); - + await page.setViewport({ height: 10, width: 10, @@ -70,15 +71,15 @@ const createScreenshot = async (filePath) => { }; -const printChangelog = function(newIcons, modifiedIcons, renamedIcons) { - if(newIcons.length > 0) { +const printChangelog = function (newIcons, modifiedIcons, renamedIcons) { + if (newIcons.length > 0) { let str = ''; str += `${newIcons.length} new icons: `; - newIcons.forEach(function(icon, i){ + newIcons.forEach(function (icon, i) { str += `\`${icon}\``; - if((i + 1) <= newIcons.length - 1) { + if ((i + 1) <= newIcons.length - 1) { str += ', ' } }); @@ -87,14 +88,14 @@ const printChangelog = function(newIcons, modifiedIcons, renamedIcons) { console.log(''); } - if(modifiedIcons.length > 0) { + if (modifiedIcons.length > 0) { let str = ''; str += `Fixed icons: `; - modifiedIcons.forEach(function(icon, i){ + modifiedIcons.forEach(function (icon, i) { str += `\`${icon}\``; - if((i + 1) <= modifiedIcons.length - 1) { + if ((i + 1) <= modifiedIcons.length - 1) { str += ', ' } }); @@ -103,18 +104,65 @@ const printChangelog = function(newIcons, modifiedIcons, renamedIcons) { console.log(''); } - if(renamedIcons.length > 0) { + if (renamedIcons.length > 0) { console.log(`Renamed icons: `); - renamedIcons.forEach(function(icon, i){ + renamedIcons.forEach(function (icon, i) { console.log(`- \`${icon[0]}\` renamed to \`${icon[1]}\``); }); } }; +const generateIconsPreview = function(files, destFile, cb, columnsCount = 17) { + + const padding = 29, + paddingOuter = 5, + iconSize = 24; + + const iconsCount = files.length, + rowsCount = Math.ceil(iconsCount / columnsCount), + width = columnsCount * (iconSize + padding) + 2 * paddingOuter - padding, + height = rowsCount * (iconSize + padding) + 2 * paddingOuter - padding; + + let svgContentSymbols = '', + svgContentIcons = '', + x = paddingOuter, + y = paddingOuter; + + files.forEach(function (file, i) { + let name = path.basename(file, '.svg'); + let svgFile = fs.readFileSync(file), + svgFileContent = svgFile.toString(); -gulp.task('build-zip', function() { + svgFileContent = svgFileContent + .replace('', '') + .replace(/\n\s+/g, ''); + + svgContentSymbols += `\t${svgFileContent}\n`; + svgContentIcons += `\t\n`; + + x += padding + iconSize; + + if (i % columnsCount === columnsCount - 1) { + x = paddingOuter; + y += padding + iconSize; + } + }); + + const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; + + fs.writeFileSync(destFile, svgContent); + createScreenshot(destFile); + + cb(); +}; + +//********************************************************************************************* + +gulp.task('build-zip', function () { const version = p.version; return gulp.src('{icons/**/*,icons-png/**/*,tabler-sprite.svg,tabler-sprite-nostroke.svg}') @@ -122,20 +170,20 @@ gulp.task('build-zip', function() { .pipe(gulp.dest('packages')) }); -gulp.task('build-jekyll', function(cb){ - cp.exec('bundle exec jekyll build', function() { +gulp.task('build-jekyll', function (cb) { + cp.exec('bundle exec jekyll build', function () { cb(); }); }); -gulp.task('build-copy', function(cb){ - cp.exec('mkdir -p icons/ && rm -fd ./icons/* && cp ./_site/icons/* ./icons', function() { +gulp.task('build-copy', function (cb) { + cp.exec('mkdir -p icons/ && rm -fd ./icons/* && cp ./_site/icons/* ./icons', function () { cb(); }); }); -gulp.task('clean-png', function(cb){ - cp.exec('rm -fd ./icons-png/*', function() { +gulp.task('clean-png', function (cb) { + cp.exec('rm -fd ./icons-png/*', function () { cb(); }); }); @@ -169,49 +217,11 @@ gulp.task('icons-sprite', function (cb) { }); gulp.task('icons-preview', function (cb) { - const columnsCount = 17, - padding = 29, - paddingOuter = 5, - iconSize = 24; glob("_site/icons/*.svg", {}, function (er, files) { - const iconsCount = files.length, - rowsCount = Math.ceil(iconsCount / columnsCount), - width = columnsCount * (iconSize + padding) + 2 * paddingOuter - padding, - height = rowsCount * (iconSize + padding) + 2 * paddingOuter - padding; - - let svgContentSymbols = '', - svgContentIcons = '', - x = paddingOuter, - y = paddingOuter; - files.forEach(function (file, i) { - let name = path.basename(file, '.svg'); - - let svgFile = fs.readFileSync(file), - svgFileContent = svgFile.toString(); - - svgFileContent = svgFileContent - .replace('', '') - .replace(/\n\s+/g, ''); + console.log('files', files); - svgContentSymbols += `\t${svgFileContent}\n`; - svgContentIcons += `\t\n`; - - x += padding + iconSize; - - if (i % columnsCount === columnsCount - 1) { - x = paddingOuter; - y += padding + iconSize; - } - }); - - const svgContent = `\n${svgContentSymbols}\n${svgContentIcons}\n`; - - fs.writeFileSync('.github/icons.svg', svgContent); - createScreenshot('.github/icons.svg'); - cb(); + generateIconsPreview(files, '.github/icons.svg', cb); }); }); @@ -229,7 +239,7 @@ gulp.task('icons-stroke', gulp.series('build-jekyll', function (cb) { let svgContentSymbols = '', svgContentIcons = '', x = paddingOuter; - + strokes.forEach(function (stroke) { let svgFileContentStroked = svgFileContent .replace('