diff options
author | tijmenvangulik <tijmen@vangulik.org> | 2021-04-10 10:34:00 +0200 |
---|---|---|
committer | tijmenvangulik <tijmen@vangulik.org> | 2021-04-10 10:34:00 +0200 |
commit | c0f30068c2f46e7015cea7e45e08bf902a2815d9 (patch) | |
tree | 4ac13bf633b5ea40cb0b9391f2883b29d442d727 /gulpfile.js | |
parent | Corrected wrong encoded unicode characters in css (diff) | |
download | tabler-icons-c0f30068c2f46e7015cea7e45e08bf902a2815d9.tar.xz |
Moved compileFonts properties from package to separate file
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/gulpfile.js b/gulpfile.js index 5d57298d..9468d785 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,6 +18,40 @@ const gulp = require('gulp'), svgpath = require('svgpath'), svgr = require('@svgr/core').default; +let compileOptions = { + includeIcons: [], + strokeWidth: null, + fontForge: "fontforge" +}; + +if (fs.existsSync('./compile-options.json')) { + try { + let tempOptions = require('./compile-options'); + if (typeof tempOptions!="object") + throw "Compile options file does not contain an json object"; + + if (typeof tempOptions.includeIcons!="undefined") { + if (!Array.isArray(tempOptions.includeIcons)) + throw "property inludeIcons is not an array"; + compileOptions.includeIcons= tempOptions.includeIcons; + } + if (typeof tempOptions.strokeWidth!="undefined") { + if (typeof tempOptions.strokeWidth!="string" && typeof tempOptions.strokeWidth!="number") + throw "property strokeWidth is not a string or number"; + compileOptions.strokeWidth=tempOptions.strokeWidth.toString(); + } + if (typeof tempOptions.fontForge!="undefined") { + if (typeof tempOptions.fontForge!="string") + throw "property fontForge is not a string"; + compileOptions.fontForge=tempOptions.fontForge; + } + + } catch (error) { + throw `Error reading compile-options.json: ${error}` + } + +} + async function asyncForEach(array, callback) { for (let index = 0; index < array.length; index++) { await callback(array[index], index, array); @@ -191,7 +225,6 @@ gulp.task('iconfont-clean', function (cb) { cb(); }); }); -const includeIcons=typeof p.compileFonts=='object'? p.compileFonts.include:[]; gulp.task('iconfont-svg-outline', function (cb) { @@ -203,39 +236,39 @@ gulp.task('iconfont-svg-outline', function (cb) { if (fs.existsSync('./.build/iconfont-unicode.json')) { iconfontUnicode = require('./.build/iconfont-unicode'); } - + await asyncForEach(files, async function (file) { const name = path.basename(file, '.svg'); - if (!Array.isArray( includeIcons) || includeIcons.length==0 || includeIcons.indexOf(name)>=0) { + if (compileOptions.includeIcons.length==0 || compileOptions.includeIcons.indexOf(name)>=0) { unicode = iconfontUnicode[name]; - await console.log('Stroke for:', file, unicode); - - let strokedSVG = fs.readFileSync(file).toString(); - - strokedSVG = strokedSVG - .replace('width="24"', 'width="1000"') - .replace('height="24"', 'height="1000"'); - if (typeof p.compileFonts=='object' && typeof p.compileFonts.strokeWidth=="string") - strokedSVG = strokedSVG.replace('stroke-width="2"', `stroke-width="${p.compileFonts.strokeWidth}"`); - - await outlineStroke(strokedSVG, { - optCurve: false, - steps: 4, - round: 0, - centerHorizontally: true, - fixedWidth: true, - color: 'black' - }).then(outlined => { - if (unicode) { - fs.writeFileSync(`icons-outlined/u${unicode.toUpperCase()}-${name}.svg`, outlined); - } else { - fs.writeFileSync(`icons-outlined/${name}.svg`, outlined); - } - }).catch(error => console.log(error)); + await console.log('Stroke for:', file, unicode); + + let strokedSVG = fs.readFileSync(file).toString(); + + strokedSVG = strokedSVG + .replace('width="24"', 'width="1000"') + .replace('height="24"', 'height="1000"'); + if (compileOptions.strokeWidth) + strokedSVG = strokedSVG.replace('stroke-width="2"', `stroke-width="${compileOptions.strokeWidth}"`); + + await outlineStroke(strokedSVG, { + optCurve: false, + steps: 4, + round: 0, + centerHorizontally: true, + fixedWidth: true, + color: 'black' + }).then(outlined => { + if (unicode) { + fs.writeFileSync(`icons-outlined/u${unicode.toUpperCase()}-${name}.svg`, outlined); + } else { + fs.writeFileSync(`icons-outlined/${name}.svg`, outlined); + } + }).catch(error => console.log(error)); } }); @@ -251,9 +284,7 @@ gulp.task('iconfont-optimize', function() { }); gulp.task('iconfont-fix-outline', function(cb) { - var fontForge= 'fontforge'; - if (typeof p.compileFonts=='object' && typeof p.compileFonts.fontForge=='string') - fontForge=p.compileFonts.fontForge; + var fontForge= compileOptions.fontForge; // correct svg outline directions in a child process using fontforge const generate = cp.spawn(fontForge, ["-lang=py", "-script", "./fix-outline.py"], { stdio: 'inherit' }); |