Migrate SVG Icons JSON generation from Grunt

This commit is contained in:
Yotam Shapira 2022-07-17 18:46:57 +03:00
parent a8fb5bc0da
commit 9c22c3c2a5
6 changed files with 317 additions and 2562 deletions

1
.gitignore vendored
View file

@ -12,6 +12,7 @@ yarn.lock

# Generated code
css
eicons.json

*.log
*.map

View file

@ -1,69 +0,0 @@
const fs = require( 'fs' );
const path = require( 'path' );
const sass = require( 'node-sass' );

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

require( 'matchdep' ).filterDev( 'grunt-*' ).forEach( grunt.loadNpmTasks );

// Project configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),

banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("dd-mm-yyyy") %> */',

usebanner: {
dist: {
options: {
banner: '<%= banner %>'
},
files: {
src: [
'css/*.min.css'
]
}
}
},

watch: {
styles: {
files: [
'scss/**/*.scss'
],
tasks: [ 'styles' ]
}
}
} );

// 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',
'generate-svg-icons-json'
] );

grunt.registerTask( 'styles', [
'usebanner'
] );
};

File diff suppressed because one or more lines are too long

2781
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,19 +5,13 @@
"author": "Elementor",
"homepage": "https://elementor.com/",
"scripts": {
"build": "npm run sass && npm run postcss && npx grunt",
"build": "npm run sass && npm run postcss && npm run generate-svg-icons-json",
"generate-svg-icons-json": "node scripts/svgIconsJsonGenerator.js",
"postcss": "node scripts/postcss.js",
"sass": "node scripts/sass.js"
},
"devDependencies": {
"autoprefixer": "~6.3.5",
"cssnano": "~3.5.2",
"grunt": "^0.4.5",
"grunt-banner": "~0.6.0",
"grunt-cli": "^1.4.3",
"grunt-contrib-uglify": "~1.0.1",
"grunt-contrib-watch": "^1.0.0",
"matchdep": "~1.0.1",
"node-sass": "^7.0.1",
"postcss": "5.2.17"
}

View file

@ -0,0 +1,17 @@
const fs = require('fs');

const svgIconsJsonPath = 'eicons.json',
configJsonPath = '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 ) );