From 727a26617b543a1da559d28e9d5757230014a527 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 19 Jan 2022 04:06:54 +0300 Subject: Extend compile options #181 --- gulpfile.js | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 037f7692..2b2c5d0f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,7 +18,7 @@ const gulp = require('gulp'), svgpath = require('svgpath'), svgr = require('@svgr/core').default; -let compileOptions = { +const compileOptions = { includeIcons: [], strokeWidth: null, fontForge: "fontforge" @@ -26,28 +26,57 @@ let compileOptions = { if (fs.existsSync('./compile-options.json')) { try { - let tempOptions = require('./compile-options'); - if (typeof tempOptions!="object") { + const tempOptions = require('./compile-options.json'); + if (typeof tempOptions !== "object") { throw "Compile options file does not contain an json object"; } - if (typeof tempOptions.includeIcons!="undefined") { + if (typeof tempOptions.includeIcons !== "undefined") { if (!Array.isArray(tempOptions.includeIcons)) { throw "property inludeIcons is not an array"; } - compileOptions.includeIcons= tempOptions.includeIcons; + compileOptions.includeIcons = tempOptions.includeIcons; } - if (typeof tempOptions.strokeWidth!="undefined") { - if (typeof tempOptions.strokeWidth!="string" && typeof tempOptions.strokeWidth!="number") { + + if (typeof tempOptions.includeCategories !== "undefined") { + if (typeof tempOptions.includeCategories === "string") { + tempOptions.includeCategories = tempOptions.includeCategories.split(' '); + } + if (!Array.isArray(tempOptions.includeCategories)) { + throw "property includeCategories is not an array or string"; + } + const tags = Object.entries(require('./tags.json')); + tempOptions.includeCategories.forEach(function (category) { + category = category.charAt(0).toUpperCase() + category.slice(1); + for (const [icon, data] of tags) { + if (data.category === category && compileOptions.includeIcons.indexOf(icon) === -1) { + compileOptions.includeIcons.push(icon); + } + } + }); + } + + if (typeof tempOptions.excludeIcons !== "undefined") { + if (!Array.isArray(tempOptions.excludeIcons)) { + throw "property excludeIcons is not an array"; + } + compileOptions.includeIcons = compileOptions.includeIcons.filter(function (icon) { + return tempOptions.excludeIcons.indexOf(icon) === -1; + }); + } + + 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(); + compileOptions.strokeWidth = tempOptions.strokeWidth.toString(); } - if (typeof tempOptions.fontForge!="undefined") { - if (typeof tempOptions.fontForge!="string") { + + if (typeof tempOptions.fontForge !== "undefined") { + if (typeof tempOptions.fontForge !== "string") { throw "property fontForge is not a string"; } - compileOptions.fontForge=tempOptions.fontForge; + compileOptions.fontForge = tempOptions.fontForge; } } catch (error) { -- cgit v1.2.1 From b36bc875e181b488b147099782520c6fd2765060 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 19 Jan 2022 04:40:51 +0300 Subject: Update README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 40281919..08fa1007 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ The default settings if you have not defined the file will be: { "includeIcons": [], "fontForge": "fontforge", - "strokeWidth": 2 + "strokeWidth": null } ``` @@ -225,16 +225,16 @@ The fontforge executable needs to be in the path or you can set the path to the ```JSON { - "fontForge":"/Applications/FontForge.app/Contents/MacOS/FontForge" + "fontForge": "/Applications/FontForge.app/Contents/MacOS/FontForge" } ``` + To compile the fonts run: ```sh npm run build-iconfont ``` -By default the stroke width is 2. You can change the stroke width in the compile-options.json - +By default the stroke width is 2. You can change the stroke width in the `compile-options.json` ```JSON { "strokeWidth": 1.5, @@ -245,9 +245,39 @@ To reduce the font file size you can choose to compile a sub set of icons. When ```JSON { - "includeIcons":["alert-octagon","alert-triangle"] + "includeIcons": ["alert-octagon", "alert-triangle"] +} +``` + +Optional property `includeCategories` - an array or string of icon categories to include, category names are case-issensetive. +```JSON +{ + "includeCategories": ["Devices", "System"] +} +``` +or +```JSON +{ + "includeCategories": "Devices System" +} +``` + +Optional property `excludeIcons` - an array of icon names using to exclude some category icons: +```JSON +{ + "includeCategories": ["system"], + "excludeIcons": ["adjustments"] } -``` +``` + +Complex solution: +```JSON +{ + "includeIcons": ["alert-octagon", "alert-triangle"], + "includeCategories": ["devices", "system"], + "excludeIcons": ["adjustments"] +} +``` ### Svelte -- cgit v1.2.1