Tweak - Creating a JSON file that holds the icons SVG data with each icon name as a key.

This commit is contained in:
Rotem Ben-Itzhak 2021-07-29 10:51:23 +03:00
parent 5ff53b4213
commit de94344ffa
2 changed files with 26 additions and 1 deletions

View file

@ -1,3 +1,6 @@
const fs = require( 'fs' );
const path = require( 'path' );

module.exports = function( grunt ) {
'use strict';

@ -83,9 +86,30 @@ module.exports = function( grunt ) {
}
} );

// Generating a JSON file that holds the icons SVG data, with each icon name as a key.
grunt.registerTask( 'generate-svg-icons-json', () => {
const rootPath = path.resolve( __dirname, './' ),
svgIconsJsonPath = path.join( rootPath, 'eicons.json' ),
configJsonPath = path.join( rootPath, 'config.json' ),
configJsonContent = JSON.parse( fs.readFileSync( configJsonPath ) ),
svgIconsJsonContent = {};

configJsonContent.glyphs.forEach( ( obj ) => {
// Currently there are no 'height' values in the config file.
if ( ! obj.svg.height ) {
obj.svg.height = obj.svg.width;
}

svgIconsJsonContent[ obj.css ] = obj.svg;
} );

fs.writeFileSync( svgIconsJsonPath, JSON.stringify( svgIconsJsonContent ) );
} );

// Default task(s).
grunt.registerTask( 'default', [
'styles'
'styles',
'generate-svg-icons-json'
] );

grunt.registerTask( 'styles', [

1
eicons.json Normal file

File diff suppressed because one or more lines are too long