|
| 1 | +import { defineConfig, type RegistryItem } from 'jsrepo'; |
| 2 | +import { output } from '@jsrepo/shadcn'; |
| 3 | +import { type Category, componentMetadata, type Variant } from './src/constants/Information'; |
| 4 | + |
| 5 | +export default defineConfig({ |
| 6 | + registry: { |
| 7 | + name: '@react-bits', |
| 8 | + description: |
| 9 | + 'An open source collection of animated, interactive & fully customizable React components for building stunning, memorable user interfaces.', |
| 10 | + homepage: 'https://reactbits.dev', |
| 11 | + authors: ['David Haz'], |
| 12 | + bugs: 'https://github.com/DavidHDev/react-bits/issues', |
| 13 | + repository: 'https://github.com/DavidHDev/react-bits', |
| 14 | + tags: [ |
| 15 | + 'react', |
| 16 | + 'javascript', |
| 17 | + 'components', |
| 18 | + 'web', |
| 19 | + 'reactjs', |
| 20 | + 'css-animations', |
| 21 | + 'component-library', |
| 22 | + 'ui-components', |
| 23 | + '3d', |
| 24 | + 'ui-library', |
| 25 | + 'tailwind', |
| 26 | + 'tailwindcss', |
| 27 | + 'components', |
| 28 | + 'components-library' |
| 29 | + ], |
| 30 | + excludeDeps: ['react'], |
| 31 | + outputs: [output({ dir: 'public/r', format: true })], |
| 32 | + items: [ |
| 33 | + ...Object.values(componentMetadata).map(component => |
| 34 | + defineComponent({ |
| 35 | + title: component.name, |
| 36 | + description: component.description, |
| 37 | + category: component.category, |
| 38 | + categories: [component.category], |
| 39 | + meta: component.meta, |
| 40 | + variants: component.variants |
| 41 | + }) |
| 42 | + ) |
| 43 | + ].flat() |
| 44 | + } |
| 45 | +}); |
| 46 | + |
| 47 | +/** |
| 48 | + * Define a component to be exposed from the registry. Creates the 4 different variants of the component and ensures the correct files are included. |
| 49 | + * |
| 50 | + * @param title The title of the component. |
| 51 | + * @param description The description of the component. |
| 52 | + * @param category The category of the component. |
| 53 | + * @param categories Organize the component into multiple categories. |
| 54 | + * @param meta Optional meta data for the component. |
| 55 | + * @param variants The variants of the component that are available through the registry (default: all variants) |
| 56 | + * @returns An array of RegistryItem objects. |
| 57 | + */ |
| 58 | +function defineComponent({ |
| 59 | + title, |
| 60 | + description, |
| 61 | + category, |
| 62 | + categories, |
| 63 | + meta, |
| 64 | + variants = ['JS-CSS', 'JS-TW', 'TS-CSS', 'TS-TW'] |
| 65 | +}: { |
| 66 | + title: string; |
| 67 | + description: string; |
| 68 | + category: Category; |
| 69 | + categories?: string[]; |
| 70 | + meta?: Record<string, string>; |
| 71 | + variants?: readonly Variant[]; |
| 72 | +}): RegistryItem[] { |
| 73 | + const baseItem: Omit<RegistryItem, 'files' | 'name'> = { |
| 74 | + title, |
| 75 | + description, |
| 76 | + type: 'registry:component', |
| 77 | + categories: [category, ...(categories ?? [])], |
| 78 | + meta |
| 79 | + }; |
| 80 | + |
| 81 | + // this might warrant a bit of explanation |
| 82 | + // basically we check if the variant is included in the variants array and if so we return the item as part of an array |
| 83 | + // otherwise we return an empty array |
| 84 | + // we then spread that array empty or otherwise into the return array |
| 85 | + return [ |
| 86 | + // JS + CSS |
| 87 | + ...(variants.includes('JS-CSS') |
| 88 | + ? [ |
| 89 | + { |
| 90 | + ...baseItem, |
| 91 | + name: `${baseItem.title}-JS-CSS`, |
| 92 | + files: [ |
| 93 | + { |
| 94 | + path: `src/content/${category}/${title}` |
| 95 | + } |
| 96 | + ] |
| 97 | + } |
| 98 | + ] |
| 99 | + : []), |
| 100 | + |
| 101 | + // JS + Tailwind |
| 102 | + ...(variants.includes('JS-TW') |
| 103 | + ? [ |
| 104 | + { |
| 105 | + ...baseItem, |
| 106 | + name: `${baseItem.title}-JS-TW`, |
| 107 | + files: [ |
| 108 | + { |
| 109 | + path: `src/tailwind/${category}/${title}` |
| 110 | + } |
| 111 | + ] |
| 112 | + } |
| 113 | + ] |
| 114 | + : []), |
| 115 | + |
| 116 | + // TS + CSS |
| 117 | + ...(variants.includes('TS-CSS') |
| 118 | + ? [ |
| 119 | + { |
| 120 | + ...baseItem, |
| 121 | + name: `${baseItem.title}-TS-CSS`, |
| 122 | + files: [ |
| 123 | + { |
| 124 | + path: `src/ts-default/${category}/${title}` |
| 125 | + } |
| 126 | + ] |
| 127 | + } |
| 128 | + ] |
| 129 | + : []), |
| 130 | + |
| 131 | + // TS + Tailwind |
| 132 | + ...(variants.includes('TS-TW') |
| 133 | + ? [ |
| 134 | + { |
| 135 | + ...baseItem, |
| 136 | + name: `${baseItem.title}-TS-TW`, |
| 137 | + files: [ |
| 138 | + { |
| 139 | + path: `src/ts-tailwind/${category}/${title}` |
| 140 | + } |
| 141 | + ] |
| 142 | + } |
| 143 | + ] |
| 144 | + : []) |
| 145 | + ]; |
| 146 | +} |
0 commit comments