@gravityforms/gulp-tasks
Version:
Configurable Gulp tasks for use in Gravity Forms projects.
72 lines (63 loc) • 3.1 kB
JavaScript
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import getConfig from '../../config.js';
import iconConfig from '../utils/icon-config.js';
import { trailingSlashIt } from '../utils/tools.js';
const cjsRequire = createRequire( import.meta.url );
const gulp = cjsRequire( 'gulp' );
const header = cjsRequire( 'gulp-header' );
const __dirname = path.dirname( fileURLToPath( import.meta.url ) );
const { config } = getConfig();
const designTokensPath = path.resolve( __dirname, '../../../design-tokens' );
const {
childDir = '',
designTokenDir = '',
parentDir = '',
target = 'admin',
targetCssDir = '',
} = iconConfig;
export default Object.assign( {}, {
iconsStyle() {
const parentDirPath = parentDir ? `${ parentDir }/` : '';
const targetCssDirPath = targetCssDir ? targetCssDir : target;
const childDirPath = childDir ? `/${ childDir }` : '';
return gulp.src( `${ config.paths.css_src }/${ parentDirPath }${ targetCssDirPath }${ childDirPath }/icons/_icons.pcss` )
.pipe( header( `/* stylelint-disable */
/* -----------------------------------------------------------------------------
*
* ${ target.charAt( 0 ).toUpperCase() + target.slice( 1 ) } Font Icons (via IcoMoon)
*
* This file is generated using the \`gulp icons\` task. Do not edit it directly.
*
* ----------------------------------------------------------------------------- */
` ) )
.pipe( gulp.dest( `${ config.paths.css_src }/${ parentDirPath }${ targetCssDirPath }${ childDirPath }/icons/` ) );
},
iconsVariables() {
const parentDirPath = parentDir ? `${ parentDir }/` : '';
const targetCssDirPath = targetCssDir ? targetCssDir : target;
const childDirPath = childDir ? `/${ childDir }` : '';
if ( designTokensPath && designTokenDir ) {
return gulp.src( `${ trailingSlashIt( designTokensPath ) }${ trailingSlashIt( designTokenDir ) }custom-properties/${ parentDirPath }${ target }${ childDirPath }/icons.js` )
.pipe( header( `/**
* ${ target.charAt( 0 ).toUpperCase() + target.slice( 1 ) } Icons (via IcoMoon)
*
* This file is generated using the \`npm run icons\` task. Do not edit it directly.
*/
module.exports = {` ) )
.pipe( gulp.dest( `${ trailingSlashIt( designTokensPath ) }${ trailingSlashIt( designTokenDir ) }custom-properties/${ parentDirPath }${ target }${ childDirPath }/` ) );
}
return gulp.src( `${ config.paths.css_src }/${ parentDirPath }${ targetCssDirPath }${ childDirPath }/variables/_icons.pcss` )
.pipe( header( `/* stylelint-disable */
/* -----------------------------------------------------------------------------
*
* Variables: ${ target.charAt( 0 ).toUpperCase() + target.slice( 1 ) } Icons (via IcoMoon)
*
* This file is generated using the \`npm run icons\` task. Do not edit it directly.
*
* ----------------------------------------------------------------------------- */
:root {` ) )
.pipe( gulp.dest( `${ config.paths.css_src }/${ parentDirPath }${ targetCssDirPath }${ childDirPath }/variables/` ) );
},
}, config?.tasks?.builtins?.header || {} );