build.mjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env node
  2. import { buildIcons } from '../../.build/build-icons.mjs'
  3. const componentTemplate = ({
  4. name,
  5. children,
  6. stringify
  7. }) => {
  8. return `\
  9. <script lang="ts">
  10. import Icon from '../Icon.svelte';
  11. const iconNode = ${JSON.stringify(children)};
  12. </script>
  13. <Icon name="${name}" {...$$props} iconNode={iconNode}>
  14. <slot/>
  15. </Icon>
  16. `;
  17. };
  18. const indexItemTemplate = ({
  19. name,
  20. namePascal
  21. }) => `export { default as ${namePascal} } from './icons/${namePascal}.svelte';`
  22. const typeDefinitionsTemplate = () => `/// <reference types="svelte" />
  23. /// <reference types="svelte2tsx/svelte-jsx" />
  24. import { SvelteComponentTyped } from "svelte";
  25. interface IconProps extends Partial<svelte.JSX.SVGProps<SVGSVGElement>> {
  26. color?: string
  27. size?: number,
  28. stroke?: number,
  29. class?: string
  30. }
  31. interface IconEvents {
  32. [evt: string]: CustomEvent<any>;
  33. }
  34. export type Icon = SvelteComponentTyped<IconProps, IconEvents, {}>
  35. // Generated icons`
  36. const indexTypeTemplate = ({
  37. namePascal
  38. }) => `export declare class ${namePascal} extends SvelteComponentTyped<IconProps, IconEvents, {}> {}`
  39. buildIcons({
  40. name: 'icons-svelte',
  41. componentTemplate,
  42. indexItemTemplate,
  43. typeDefinitionsTemplate,
  44. indexTypeTemplate,
  45. extension: 'svelte',
  46. pretty: false,
  47. key: false
  48. })