UNPKG

@gravityforms/gulp-tasks

Version:
72 lines (63 loc) 1.89 kB
const getConfig = require( '../../config' ); const { config } = getConfig(); const args = require( '../utils/get-args' ); /** * @function stylelintProcess * @description Run stylelint based on the options provided. * @async * @param {object} options Options object. * @param {Array<object>} options.stylelintConfig Array of objects containing stylelint configurations. * @return {Promise} */ async function stylelintProcess( { stylelintConfig } ) { const { default: stylelint } = await import( 'stylelint' ); let anyErrored = false; await Promise.all( stylelintConfig.map( async ( configObj ) => { const { src } = configObj; const result = await stylelint.lint( { files: src, fix: false, // ! args.nofix if you want to use args again, but it can cause issues. formatter: 'string', } ); if ( result.report ) { process.stderr.write( result.report ); } if ( result.errored ) { anyErrored = true; } } ) ); if ( anyErrored ) { throw new Error( 'Stylelint found errors (see above).' ); } } module.exports = Object.assign( {}, { admin() { const stylelintConfig = config?.stylelint?.adminCss || [ { src: [ `${ config.paths.css_src }/admin/**/*.pcss` ], dest: `${ config.paths.css_src }/admin/`, } ]; return stylelintProcess( { stylelintConfig, } ); }, common() { const stylelintConfig = config?.stylelint?.commonCss || [ { src: [ `${ config.paths.css_src }/common/**/*.pcss` ], dest: `${ config.paths.css_src }/common/`, } ]; return stylelintProcess( { stylelintConfig, } ); }, theme() { const stylelintConfig = config?.stylelint?.themeCss || [ { src: [ `${ config.paths.css_src }/theme/**/*.pcss` ], dest: `${ config.paths.css_src }/theme/`, } ]; return stylelintProcess( { stylelintConfig, } ); }, }, config?.tasks?.builtins?.stylelint || {} );