aboutsummaryrefslogtreecommitdiff
path: root/gulpfile.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.js')
-rw-r--r--gulpfile.js49
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()
}))