build.mjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env node
  2. import { buildIcons } from '../../.build/build-icons.mjs'
  3. const componentTemplate = ({
  4. name,
  5. namePascal,
  6. children
  7. }) => `\
  8. import createReactComponent from '../createReactComponent';
  9. export default createReactComponent('${name}', '${namePascal}', ${JSON.stringify(children)});`;
  10. const indexItemTemplate = ({
  11. name,
  12. namePascal
  13. }) => `export { default as ${namePascal} } from './icons/${name}';`
  14. const typeDefinitionsTemplate = () => `/// <reference types="react" />
  15. import { SVGAttributes } from 'react'
  16. declare module '@tabler/icons-react'
  17. // Create interface extending SVGProps
  18. export interface TablerIconsProps extends Partial<React.SVGProps<SVGSVGElement>> {
  19. size?: string | number
  20. }
  21. export declare const createReactComponent: (iconName: string, iconNode: any[]) => (props: TablerIconsProps) => JSX.Element;
  22. export type Icon = React.FC<TablerIconsProps>;
  23. // Generated icons`
  24. const indexTypeTemplate = ({
  25. namePascal
  26. }) => `export declare const ${namePascal}: (props: TablerIconsProps) => JSX.Element;`
  27. buildIcons({
  28. name: 'icons-react',
  29. componentTemplate,
  30. indexItemTemplate,
  31. typeDefinitionsTemplate,
  32. indexTypeTemplate
  33. })