aboutsummaryrefslogtreecommitdiff
path: root/gulpfile.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js105
1 files changed, 79 insertions, 26 deletions
diff --git a/gulpfile.js b/gulpfile.js
index 9f541ab7..60203d7e 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -18,6 +18,44 @@ 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);
@@ -204,31 +242,40 @@ gulp.task('iconfont-svg-outline', function (cb) {
}
await asyncForEach(files, async function (file) {
- const name = path.basename(file, '.svg'),
+
+ const name = path.basename(file, '.svg');
+
+ 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"');
-
- 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);
+ 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}"`);
}
- }).catch(error => console.log(error));
+
+ 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));
+ }
+
});
cb();
@@ -242,8 +289,10 @@ gulp.task('iconfont-optimize', function() {
});
gulp.task('iconfont-fix-outline', function(cb) {
+ 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' });
+ const generate = cp.spawn(fontForge, ["-lang=py", "-script", "./fix-outline.py"], { stdio: 'inherit' });
generate.on("close", function (code) {
console.log(`Correcting svg outline directions exited with code ${code}`);
if (!code) {
@@ -354,8 +403,12 @@ gulp.task('build-zip', function () {
});
gulp.task('build-jekyll', function (cb) {
- cp.exec('bundle exec jekyll build', function () {
- cb();
+ const jekyll = cp.spawn("bundle", ["exec", "jekyll", "build"], { stdio: 'inherit' });
+ jekyll.on("close", function (code) {
+ console.log(`Jekyll build exited with code ${code}`);
+ if (!code) {
+ cb();
+ }
});
});
@@ -668,7 +721,7 @@ const setVersions = function(version, files) {
if(!svgFile.match(/version: ([0-9.]+)/i)) {
svgFile = svgFile.replace(/---\n<svg>/i, function(m){
- return `version: ${version}\n${m}`;
+ return `version: "${version}"\n${m}`;
});
fs.writeFileSync(`src/_icons/${file}.svg`, svgFile);