diff options
author | codecalm <codecalm@gmail.com> | 2022-04-16 14:50:51 +0200 |
---|---|---|
committer | codecalm <codecalm@gmail.com> | 2022-04-16 14:50:51 +0200 |
commit | c291772a85d309a32896ce7d616157d93e631408 (patch) | |
tree | 19c9596f3e85df49c11f62cb099a3d7e3391926b /gulpfile.js | |
parent | Merge branch 'master' of https://github.com/tabler/tabler-icons into v2.0 (diff) | |
download | tabler-icons-c291772a85d309a32896ce7d616157d93e631408.tar.xz |
icons-react build
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 49 |
1 files changed, 2 insertions, 47 deletions
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('<path stroke="none" d="M0 0h24v24H0z"/>', '') - } - - let indexCode = '', - indexDCode = `import { FC, SVGAttributes } from 'react';\n\ninterface TablerIconProps extends SVGAttributes<SVGElement> { color?: string; size?: string | number; stroke?: string | number; }\n\ntype TablerIcon = FC<TablerIconProps>;\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() })) |