build.mjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/${namePascal}';`
  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<Omit<React.SVGProps<SVGSVGElement>, 'stroke'>> {
  19. size?: string | number,
  20. stroke?: string | number
  21. }
  22. export declare const createReactComponent: (iconName: string, iconNamePascal: string, iconNode: any[]) => (props: TablerIconsProps) => JSX.Element;
  23. export type Icon = React.FC<TablerIconsProps>;
  24. // Generated icons`
  25. const indexTypeTemplate = ({
  26. namePascal
  27. }) => `export declare const ${namePascal}: (props: TablerIconsProps) => JSX.Element;`
  28. buildIcons({
  29. name: 'icons-react',
  30. componentTemplate,
  31. indexItemTemplate,
  32. typeDefinitionsTemplate,
  33. indexTypeTemplate,
  34. pascalCase: true
  35. })