From c291772a85d309a32896ce7d616157d93e631408 Mon Sep 17 00:00:00 2001 From: codecalm Date: Sat, 16 Apr 2022 14:50:51 +0200 Subject: icons-react build --- gulpfile.js | 49 ++----------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index d86a965d..7123ab54 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -52,7 +52,7 @@ if (fs.existsSync('./compile-options.json')) { } }) } - + if (typeof tempOptions.excludeIcons !== "undefined") { if (!Array.isArray(tempOptions.excludeIcons)) { throw "property excludeIcons is not an array" @@ -89,11 +89,7 @@ if (fs.existsSync('./compile-options.json')) { } -async function asyncForEach (array, callback) { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array) - } -} + const svgToPng = async (filePath, destination) => { filePath = path.join(__dirname, filePath) @@ -592,48 +588,7 @@ gulp.task('clean-react', function (cb) { }) gulp.task('svg-to-react', gulp.series('clean-react', async function (cb) { - let files = glob.sync("./icons/*.svg") - - const camelize = function (str) { - str = str.replace(/-/g, ' ') - - return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) { - return word.toUpperCase() - }).replace(/\s+/g, '') - } - const componentName = function (file) { - file = path.basename(file, '.svg') - file = camelize(`Icon ${file}`) - - return file - } - - const optimizeSvgCode = function (svgCode) { - return svgCode.replace('', '') - } - - let indexCode = '', - indexDCode = `import { FC, SVGAttributes } from 'react';\n\ninterface TablerIconProps extends SVGAttributes { color?: string; size?: string | number; stroke?: string | number; }\n\ntype TablerIcon = FC;\n\n` - - await asyncForEach(files, async function (file) { - const svgCode = optimizeSvgCode(fs.readFileSync(file).toString()), - fileName = path.basename(file, '.svg') + '.js', - iconComponentName = componentName(file) - - await svgr(svgCode, { - icon: false, - svgProps: { width: '{size}', height: '{size}', strokeWidth: '{stroke}', stroke: '{color}' }, - template: require('./.build/svgr-template') - }, { componentName: iconComponentName }).then(jsCode => { - fs.writeFileSync('icons-react/icons-js/' + fileName, jsCode) - indexCode += `export { default as ${iconComponentName} } from './icons-js/${fileName}';\n` - indexDCode += `export const ${iconComponentName}: TablerIcon;\n` - }) - - fs.writeFileSync('icons-react/index.js', indexCode) - fs.writeFileSync('icons-react/index.d.ts', indexDCode) - }) cb() })) -- cgit v1.2.1