Add ESLint Support

This commit is contained in:
Yotam Shapira 2022-07-28 21:37:00 +03:00
parent ecc1989d98
commit 6d52fa684f
7 changed files with 3757 additions and 37 deletions

1
.eslintignore Normal file
View file

@ -0,0 +1 @@
css

20
.eslintrc.js Normal file
View file

@ -0,0 +1,20 @@
module.exports = {
extends: [
'plugin:@wordpress/eslint-plugin/recommended-with-formatting',
],
plugins: [],
globals: {
},
parserOptions: {
ecmaVersion: 2017,
requireConfigFile: false,
sourceType: 'module',
},
rules: {
},
settings: {
jsdoc: {
mode: 'typescript',
},
},
};

3696
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,20 +5,23 @@
"author": "Elementor",
"homepage": "https://elementor.com/",
"engines": {
"node": ">=16.0.0"
},
"node": ">=16.0.0"
},
"files": [
"css/**/*"
],
"css/**/*"
],
"scripts": {
"build": "npm run sass && npm run postcss && npm run generate-svg-icons-json",
"generate-svg-icons-json": "node scripts/svgIconsJsonGenerator.mjs",
"postcss": "node scripts/postcss.mjs",
"sass": "node scripts/sass.mjs",
"prepare": "npm run build"
"prepare": "npm run build",
"lint": "eslint . --ext js,mjs"
},
"devDependencies": {
"@wordpress/eslint-plugin": "^12.8.0",
"cssnano": "^5.1.12",
"eslint": "^8.20.0",
"postcss": "^8.4.14",
"sass": "^1.53.0"
}

View file

@ -2,14 +2,14 @@ import { promises as fs } from 'fs';
import postcss from 'postcss';
import cssNano from 'cssnano';

const postCss = async (cssFilePath, outputFilePath) => {
const css = await fs.readFile(cssFilePath);
const result = await postcss([cssNano])
.process(css, { from: cssFilePath, to: outputFilePath })
await fs.writeFile(outputFilePath, result.css);
if ( result.map ) {
await fs.writeFile(outputFilePath, result.map);
}
const postCss = async ( cssFilePath, outputFilePath ) => {
const css = await fs.readFile( cssFilePath );
const result = await postcss( [ cssNano ] )
.process( css, { from: cssFilePath, to: outputFilePath } );
await fs.writeFile( outputFilePath, result.css );
if ( result.map ) {
await fs.writeFile( outputFilePath, result.map );
}
};

await postCss('css/elementor-icons.css', 'css/elementor-icons.min.css');
await postCss( 'css/elementor-icons.css', 'css/elementor-icons.min.css' );

View file

@ -1,16 +1,16 @@
import { promises as fs, constants } from 'fs';
import { promises as fs } from 'fs';
import sass from 'sass';

const compileSass = async (scssFilePath, resultsDir, cssFileName) => {
const renderResult = sass.compile(scssFilePath);
const compileSass = async ( scssFilePath, resultsDir, cssFileName ) => {
const renderResult = sass.compile( scssFilePath );

try {
await fs.access(resultsDir);
} catch (e) {
await fs.mkdir(resultsDir);
}
try {
await fs.access( resultsDir );
} catch ( e ) {
await fs.mkdir( resultsDir );
}

await fs.writeFile(`${resultsDir}/${cssFileName}`, renderResult.css);
await fs.writeFile( `${ resultsDir }/${ cssFileName }`, renderResult.css );
};

await compileSass('scss/elementor-icons.scss', 'css', 'elementor-icons.css');
await compileSass( 'scss/elementor-icons.scss', 'css', 'elementor-icons.css' );

View file

@ -1,19 +1,19 @@
import { promises as fs } from 'fs';

const generateSvgIconsJson = async (configJsonPath, svgIconsJsonPath) => {
const configJsonContent = JSON.parse( await fs.readFile( configJsonPath ) ),
svgIconsJsonContent = {};
const generateSvgIconsJson = async ( configJsonPath, svgIconsJsonPath ) => {
const configJsonContent = JSON.parse( await fs.readFile( 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;
}
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;
} );
svgIconsJsonContent[ obj.css ] = obj.svg;
} );

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

await generateSvgIconsJson('config.json', 'eicons.json');
await generateSvgIconsJson( 'config.json', 'eicons.json' );