@spaced-out/ui-design-system 0.5.18 → 0.5.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,247 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Build script to extract design system metadata into JSON
5
+ * This runs before publishing to npm to bundle all component/token data
6
+ */
7
+
8
+ import { readFileSync, writeFileSync, readdirSync, statSync, existsSync, mkdirSync } from 'fs';
9
+ import { join, resolve, dirname } from 'path';
10
+ import { fileURLToPath } from 'url';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = dirname(__filename);
14
+
15
+ // Design system is parent directory
16
+ const DESIGN_SYSTEM_PATH = resolve(__dirname, '..');
17
+ const OUTPUT_DIR = join(__dirname, 'data');
18
+ const OUTPUT_FILE = join(OUTPUT_DIR, 'design-system.json');
19
+
20
+ console.log('Building Genesis MCP data...\n');
21
+ console.log(`Design System: ${DESIGN_SYSTEM_PATH}`);
22
+ console.log(`Output: ${OUTPUT_FILE}\n`);
23
+
24
+ function safeReadFile(filePath) {
25
+ try {
26
+ return readFileSync(filePath, 'utf-8');
27
+ } catch (error) {
28
+ return null;
29
+ }
30
+ }
31
+
32
+ function getDirectories(path) {
33
+ try {
34
+ return readdirSync(path).filter(f => {
35
+ const fullPath = join(path, f);
36
+ return statSync(fullPath).isDirectory() && !f.startsWith('.');
37
+ });
38
+ } catch (error) {
39
+ console.error(`āŒ Error reading directories in ${path}:`, error.message);
40
+ return [];
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Extract all components with their files
46
+ */
47
+ function buildComponentsData() {
48
+ console.log('šŸ“¦ Extracting components...');
49
+ const componentsPath = join(DESIGN_SYSTEM_PATH, 'src/components');
50
+ const components = {};
51
+
52
+ if (!existsSync(componentsPath)) {
53
+ console.warn('āš ļø Components path not found');
54
+ return components;
55
+ }
56
+
57
+ const componentDirs = getDirectories(componentsPath).filter(name => name !== 'index.ts');
58
+
59
+ for (const componentName of componentDirs) {
60
+ const componentDir = join(componentsPath, componentName);
61
+
62
+ const mainTsx = join(componentDir, `${componentName}.tsx`);
63
+ const mainTs = join(componentDir, `${componentName}.ts`);
64
+
65
+ const storyTsx = join(componentDir, `${componentName}.stories.tsx`);
66
+ const storyTs = join(componentDir, `${componentName}.stories.ts`);
67
+
68
+ const cssFile = join(componentDir, `${componentName}.module.css`);
69
+
70
+ const indexFile = join(componentDir, 'index.ts');
71
+
72
+ const mainContent = safeReadFile(mainTsx) || safeReadFile(mainTs);
73
+ const storyContent = safeReadFile(storyTsx) || safeReadFile(storyTs);
74
+ const cssContent = safeReadFile(cssFile);
75
+ const indexContent = safeReadFile(indexFile);
76
+
77
+ const allFiles = existsSync(componentDir)
78
+ ? readdirSync(componentDir).filter(f => !f.startsWith('.'))
79
+ : [];
80
+
81
+ components[componentName] = {
82
+ name: componentName,
83
+ path: `src/components/${componentName}`,
84
+ files: {
85
+ main: mainContent ? { path: `${componentName}.tsx`, content: mainContent } : null,
86
+ story: storyContent ? { path: `${componentName}.stories.tsx`, content: storyContent } : null,
87
+ css: cssContent ? { path: `${componentName}.module.css`, content: cssContent } : null,
88
+ index: indexContent ? { path: 'index.ts', content: indexContent } : null,
89
+ },
90
+ allFiles,
91
+ };
92
+ }
93
+
94
+ console.log(` āœ… Extracted ${Object.keys(components).length} components`);
95
+ return components;
96
+ }
97
+
98
+ /**
99
+ * Extract all hooks
100
+ */
101
+ function buildHooksData() {
102
+ console.log('šŸŖ Extracting hooks...');
103
+ const hooksPath = join(DESIGN_SYSTEM_PATH, 'src/hooks');
104
+ const hooks = {};
105
+
106
+ if (!existsSync(hooksPath)) {
107
+ console.warn('āš ļø Hooks path not found');
108
+ return hooks;
109
+ }
110
+
111
+ const hookDirs = getDirectories(hooksPath).filter(name => name !== 'index.ts');
112
+
113
+ for (const hookName of hookDirs) {
114
+ const hookDir = join(hooksPath, hookName);
115
+
116
+ // Read main hook file
117
+ const mainTs = join(hookDir, `${hookName}.ts`);
118
+ const mainTsx = join(hookDir, `${hookName}.tsx`);
119
+
120
+ // Read story file
121
+ const storyTsx = join(hookDir, `${hookName}.stories.tsx`);
122
+ const storyTs = join(hookDir, `${hookName}.stories.ts`);
123
+
124
+ // Read index file
125
+ const indexFile = join(hookDir, 'index.ts');
126
+
127
+ const mainContent = safeReadFile(mainTs) || safeReadFile(mainTsx);
128
+ const storyContent = safeReadFile(storyTsx) || safeReadFile(storyTs);
129
+ const indexContent = safeReadFile(indexFile);
130
+
131
+ const allFiles = existsSync(hookDir)
132
+ ? readdirSync(hookDir).filter(f => !f.startsWith('.'))
133
+ : [];
134
+
135
+ hooks[hookName] = {
136
+ name: hookName,
137
+ path: `src/hooks/${hookName}`,
138
+ files: {
139
+ main: mainContent ? { path: `${hookName}.ts`, content: mainContent } : null,
140
+ story: storyContent ? { path: `${hookName}.stories.tsx`, content: storyContent } : null,
141
+ index: indexContent ? { path: 'index.ts', content: indexContent } : null,
142
+ },
143
+ allFiles,
144
+ };
145
+ }
146
+
147
+ console.log(` āœ… Extracted ${Object.keys(hooks).length} hooks`);
148
+ return hooks;
149
+ }
150
+
151
+ /**
152
+ * Extract all design tokens
153
+ */
154
+ function buildTokensData() {
155
+ console.log('šŸŽØ Extracting design tokens...');
156
+ const tokensPath = join(DESIGN_SYSTEM_PATH, 'design-tokens');
157
+ const tokens = {};
158
+
159
+ if (!existsSync(tokensPath)) {
160
+ console.warn('āš ļø Design tokens path not found');
161
+ return tokens;
162
+ }
163
+
164
+ const categories = getDirectories(tokensPath);
165
+
166
+ for (const category of categories) {
167
+ tokens[category] = {};
168
+ const categoryPath = join(tokensPath, category);
169
+
170
+ try {
171
+ const files = readdirSync(categoryPath).filter(f => f.endsWith('.json'));
172
+
173
+ for (const file of files) {
174
+ const filePath = join(categoryPath, file);
175
+ try {
176
+ const content = readFileSync(filePath, 'utf-8');
177
+ const tokenData = JSON.parse(content);
178
+ tokens[category][file.replace('.json', '')] = tokenData;
179
+ } catch (error) {
180
+ console.warn(` āš ļø Error parsing ${file}:`, error.message);
181
+ }
182
+ }
183
+ } catch (error) {
184
+ console.warn(` āš ļø Error reading category ${category}:`, error.message);
185
+ }
186
+ }
187
+
188
+ const tokenCount = Object.values(tokens).reduce((sum, cat) => sum + Object.keys(cat).length, 0);
189
+ console.log(` āœ… Extracted ${tokenCount} token files across ${Object.keys(tokens).length} categories`);
190
+ return tokens;
191
+ }
192
+
193
+ /**
194
+ * Get package version
195
+ */
196
+ function getVersion() {
197
+ try {
198
+ const pkgPath = join(DESIGN_SYSTEM_PATH, 'package.json');
199
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
200
+ return pkg.version || '0.0.0';
201
+ } catch (error) {
202
+ return '0.0.0';
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Main build function
208
+ */
209
+ function build() {
210
+ try {
211
+ const data = {
212
+ metadata: {
213
+ buildDate: new Date().toISOString(),
214
+ version: getVersion(),
215
+ designSystemPath: DESIGN_SYSTEM_PATH,
216
+ },
217
+ components: buildComponentsData(),
218
+ hooks: buildHooksData(),
219
+ tokens: buildTokensData(),
220
+ };
221
+
222
+ // Create output directory if it doesn't exist
223
+ if (!existsSync(OUTPUT_DIR)) {
224
+ mkdirSync(OUTPUT_DIR, { recursive: true });
225
+ }
226
+
227
+ // Write to JSON file
228
+ writeFileSync(OUTPUT_FILE, JSON.stringify(data, null, 2));
229
+
230
+ console.log('\n✨ Build complete!');
231
+ console.log(`šŸ“Š Summary:`);
232
+ console.log(` - Components: ${Object.keys(data.components).length}`);
233
+ console.log(` - Hooks: ${Object.keys(data.hooks).length}`);
234
+ console.log(` - Token categories: ${Object.keys(data.tokens).length}`);
235
+ console.log(` - Version: ${data.metadata.version}`);
236
+ console.log(` - Output: ${OUTPUT_FILE}`);
237
+ console.log(` - Size: ${(Buffer.byteLength(JSON.stringify(data)) / 1024 / 1024).toFixed(2)} MB\n`);
238
+
239
+ } catch (error) {
240
+ console.error('āŒ Build failed:', error);
241
+ process.exit(1);
242
+ }
243
+ }
244
+
245
+ // Run the build
246
+ build();
247
+