diff options
author | codecalm <codecalm@gmail.com> | 2022-04-17 20:43:39 +0200 |
---|---|---|
committer | codecalm <codecalm@gmail.com> | 2022-04-17 20:43:39 +0200 |
commit | 6a5f5bf0283458aabdcc34eb695175cfea4a632f (patch) | |
tree | 58fe67c2cc4529730890e032da903891e85d12a6 /scripts | |
parent | 2.1.0 (diff) | |
download | tabler-icons-v2.0.tar.xz |
build react scriptv2.0
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/build-preact.js | 1 | ||||
-rw-r--r-- | scripts/build-react.js | 31 | ||||
-rw-r--r-- | scripts/build-vue-2.js | 3 | ||||
-rw-r--r-- | scripts/svgr-template.js | 12 | ||||
-rw-r--r-- | scripts/utils.js | 5 |
5 files changed, 27 insertions, 25 deletions
diff --git a/scripts/build-preact.js b/scripts/build-preact.js new file mode 100644 index 00000000..908ba841 --- /dev/null +++ b/scripts/build-preact.js @@ -0,0 +1 @@ +#!/usr/bin/env node diff --git a/scripts/build-react.js b/scripts/build-react.js index 17cbb742..2aa87d0e 100644 --- a/scripts/build-react.js +++ b/scripts/build-react.js @@ -1,14 +1,23 @@ -const glob = require('glob') -const path = require('path') -const fs = require('fs') -const { default: svgr } = require('@svgr/core') -const { asyncForEach, camelize } = require('./utils') +#!/usr/bin/env node + +import glob from 'glob' +import path from 'path' +import fs from 'fs' +import svgr from '@svgr/core' +import { asyncForEach, camelize, optimizeSvgCode } from './utils' const packageDir = path.resolve(__dirname, '../packages/icons-react') -const optimizeSvgCode = function (svgCode) { - return svgCode - .replace('<path stroke="none" d="M0 0h24v24H0z" fill="none"/>', '') +const componentTemplate = function template( + { template }, + opts, + { imports, componentName, props, jsx, exports }, +) { + return template.ast` + ${imports} + function ${componentName}({ size = 24, color = "currentColor", stroke = 2, ...props }) { return (${jsx}); } + ${exports} + `; } const componentName = function (file) { @@ -33,16 +42,12 @@ type TablerIcon = FC<TablerIconProps>;\n\n` fileName = path.basename(file, '.svg') + '.js', iconComponentName = componentName(file) - if(fs.existsSync(`${packageDir}/icons/`)) { - fs.rmSync(`${packageDir}/icons/`, { recursive: true }) - } - fs.mkdirSync(`${packageDir}/icons/`, { recursive: true }) await svgr(svgCode, { icon: false, svgProps: { width: '{size}', height: '{size}', strokeWidth: '{stroke}', stroke: '{color}' }, - template: require('./svgr-template') + template: componentTemplate }, { componentName: iconComponentName }).then(jsCode => { fs.writeFileSync(`${packageDir}/icons/${fileName}`, jsCode) diff --git a/scripts/build-vue-2.js b/scripts/build-vue-2.js new file mode 100644 index 00000000..633f1e1c --- /dev/null +++ b/scripts/build-vue-2.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + + diff --git a/scripts/svgr-template.js b/scripts/svgr-template.js deleted file mode 100644 index c8c41384..00000000 --- a/scripts/svgr-template.js +++ /dev/null @@ -1,12 +0,0 @@ -function template( - { template }, - opts, - { imports, componentName, props, jsx, exports }, -) { - return template.ast` - ${imports} - function ${componentName}({ size = 24, color = "currentColor", stroke = 2, ...props }) { return (${jsx}); } - ${exports} - `; -} -module.exports = template; diff --git a/scripts/utils.js b/scripts/utils.js index 86ea64aa..f305dc72 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -12,3 +12,8 @@ export const camelize = function (str) { return word.toUpperCase() }).replace(/\s+/g, '') } + +export const optimizeSvgCode = function (svgCode) { + return svgCode + .replace('<path stroke="none" d="M0 0h24v24H0z" fill="none"/>', '') +} |