@auto-engineer/design-system-importer 0.6.5 → 0.7.0

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.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +12 -14
  3. package/.turbo/turbo-type-check.log +4 -5
  4. package/CHANGELOG.md +11 -0
  5. package/README.md +7 -11
  6. package/dist/commands/import-design-system.d.ts +12 -25
  7. package/dist/commands/import-design-system.d.ts.map +1 -1
  8. package/dist/commands/import-design-system.js +38 -29
  9. package/dist/commands/import-design-system.js.map +1 -1
  10. package/dist/figma-api.d.ts +6 -0
  11. package/dist/figma-api.d.ts.map +1 -0
  12. package/dist/figma-api.js +38 -0
  13. package/dist/figma-api.js.map +1 -0
  14. package/dist/figma-importer.d.ts +8 -0
  15. package/dist/figma-importer.d.ts.map +1 -0
  16. package/dist/figma-importer.js +76 -0
  17. package/dist/figma-importer.js.map +1 -0
  18. package/dist/file-operations.d.ts +4 -0
  19. package/dist/file-operations.d.ts.map +1 -0
  20. package/dist/file-operations.js +102 -0
  21. package/dist/file-operations.js.map +1 -0
  22. package/dist/index.d.ts +15 -17
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +7 -282
  25. package/dist/index.js.map +1 -1
  26. package/dist/markdown-generator.d.ts +7 -0
  27. package/dist/markdown-generator.d.ts.map +1 -0
  28. package/dist/markdown-generator.js +44 -0
  29. package/dist/markdown-generator.js.map +1 -0
  30. package/package.json +3 -3
  31. package/src/commands/import-design-system.ts +40 -33
  32. package/src/figma-api.ts +46 -0
  33. package/src/figma-importer.ts +91 -0
  34. package/src/file-operations.ts +113 -0
  35. package/src/index.ts +9 -333
  36. package/src/markdown-generator.ts +56 -0
  37. package/tsconfig.tsbuildinfo +1 -1
  38. package/.turbo/turbo-format.log +0 -15
  39. package/.turbo/turbo-lint.log +0 -5
  40. package/dist/cli-manifest.d.ts +0 -3
  41. package/dist/cli-manifest.d.ts.map +0 -1
  42. package/dist/cli-manifest.js +0 -35
  43. package/dist/cli-manifest.js.map +0 -1
  44. package/src/cli-manifest.ts +0 -37
@@ -0,0 +1,113 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs/promises';
3
+ import createDebug from 'debug';
4
+
5
+ const debugFiles = createDebug('design-system-importer:files');
6
+ const debugComponents = createDebug('design-system-importer:components');
7
+ const debugCopy = createDebug('design-system-importer:copy');
8
+
9
+ export async function getAllTsxFiles(dir: string): Promise<string[]> {
10
+ debugFiles('Scanning directory for TSX files: %s', dir);
11
+ let results: string[] = [];
12
+
13
+ try {
14
+ const entries = await fs.readdir(dir, { withFileTypes: true });
15
+ debugFiles('Found %d entries in %s', entries.length, dir);
16
+
17
+ for (const entry of entries) {
18
+ const fullPath = path.join(dir, entry.name);
19
+ if (entry.isDirectory()) {
20
+ debugFiles('Entering subdirectory: %s', entry.name);
21
+ const subResults = await getAllTsxFiles(fullPath);
22
+ results = results.concat(subResults);
23
+ debugFiles('Found %d TSX files in %s', subResults.length, entry.name);
24
+ } else if (entry.isFile() && entry.name.endsWith('.tsx')) {
25
+ debugFiles('Found TSX file: %s', entry.name);
26
+ results.push(fullPath);
27
+ }
28
+ }
29
+ } catch (error) {
30
+ debugFiles('Error reading directory %s: %O', dir, error);
31
+ }
32
+
33
+ debugFiles('Total TSX files found in %s: %d', dir, results.length);
34
+ return results;
35
+ }
36
+
37
+ export function getComponentNameFromFile(filePath: string): string {
38
+ debugComponents('Extracting component name from: %s', filePath);
39
+ const file = path.basename(filePath, '.tsx');
40
+ // Capitalize first letter
41
+ const componentName = file.charAt(0).toUpperCase() + file.slice(1);
42
+ debugComponents('Component name: %s', componentName);
43
+ return componentName;
44
+ }
45
+
46
+ async function copyFile(inputDir: string, outputDir: string, file: string): Promise<void> {
47
+ const srcPath = path.join(inputDir, file);
48
+ const destPath = path.join(outputDir, file);
49
+ debugCopy('Attempting to copy file: %s from %s to %s', file, inputDir, outputDir);
50
+
51
+ // Check if source file exists
52
+ try {
53
+ await fs.access(srcPath);
54
+ debugCopy('Source file exists: %s', srcPath);
55
+
56
+ debugCopy('Creating output directory: %s', outputDir);
57
+ await fs.mkdir(outputDir, { recursive: true });
58
+
59
+ await fs.copyFile(srcPath, destPath);
60
+ debugCopy('Successfully copied %s to %s', file, destPath);
61
+ } catch (error) {
62
+ // File doesn't exist, skip copying
63
+ debugCopy('File %s not found in %s, error: %O', file, inputDir, error);
64
+ console.log(`File ${file} not found in ${inputDir}, skipping...`, error);
65
+ }
66
+ }
67
+
68
+ export async function copyDesignSystemDocsAndUserPreferences(inputDir: string, outputDir: string): Promise<void> {
69
+ debugCopy('Copying design system docs from %s to %s', inputDir, outputDir);
70
+
71
+ // Ensure output directory exists
72
+ debugCopy('Creating output directory: %s', outputDir);
73
+ await fs.mkdir(outputDir, { recursive: true });
74
+
75
+ // Try to copy existing files
76
+ debugCopy('Copying design-system.md...');
77
+ await copyFile(inputDir, outputDir, 'design-system.md');
78
+
79
+ debugCopy('Copying design-system-principles.md...');
80
+ await copyFile(inputDir, outputDir, 'design-system-principles.md');
81
+
82
+ // If design-system.md doesn't exist in output, try to generate it from TSX files
83
+ const designSystemPath = path.join(outputDir, 'design-system.md');
84
+ debugCopy('Checking if design-system.md exists at: %s', designSystemPath);
85
+
86
+ try {
87
+ await fs.access(designSystemPath);
88
+ debugCopy('design-system.md already exists');
89
+ } catch {
90
+ debugCopy('design-system.md does not exist, attempting to generate from TSX files');
91
+ // File doesn't exist, try to generate from TSX files if inputDir exists
92
+ try {
93
+ await fs.access(inputDir);
94
+ debugCopy('Input directory is accessible: %s', inputDir);
95
+
96
+ const { generateDesignSystemMarkdown } = await import('./markdown-generator.js');
97
+ const files = await getAllTsxFiles(inputDir);
98
+ if (files.length > 0) {
99
+ debugCopy('Found %d TSX files, generating design-system.md', files.length);
100
+ await generateDesignSystemMarkdown(inputDir, outputDir);
101
+ console.log(`Generated design-system.md from ${files.length} component files`);
102
+ } else {
103
+ debugCopy('No TSX files found in %s', inputDir);
104
+ console.log(`No .tsx files found in ${inputDir} to generate design-system.md`);
105
+ }
106
+ } catch (error) {
107
+ debugCopy('Input directory %s not accessible: %O', inputDir, error);
108
+ console.log(`Input directory ${inputDir} not accessible`);
109
+ }
110
+ }
111
+
112
+ debugCopy('Design system docs copy/generation complete');
113
+ }
package/src/index.ts CHANGED
@@ -1,333 +1,9 @@
1
- import * as path from 'path';
2
- import * as fs from 'fs/promises';
3
- import * as dotenv from 'dotenv';
4
- import { fileURLToPath } from 'url';
5
- import * as Figma from 'figma-api';
6
- import { FigmaComponentsBuilder, type FilterFunctionType } from './FigmaComponentsBuilder';
7
- import createDebug from 'debug';
8
- // import { AIProvider, generateTextWithAI } from '@auto-engineer/ai-gateway';
9
-
10
- const debug = createDebug('design-system-importer');
11
- const debugFiles = createDebug('design-system-importer:files');
12
- const debugFigma = createDebug('design-system-importer:figma');
13
- const debugMarkdown = createDebug('design-system-importer:markdown');
14
- const debugComponents = createDebug('design-system-importer:components');
15
- const debugCopy = createDebug('design-system-importer:copy');
16
-
17
- dotenv.config();
18
- debug('Design system importer initialized');
19
-
20
- const __filename = fileURLToPath(import.meta.url);
21
-
22
- debugFigma('Initializing Figma API with personal access token');
23
- const api = new Figma.Api({
24
- personalAccessToken: process.env.FIGMA_PERSONAL_TOKEN as string,
25
- });
26
- debugFigma('Figma API initialized');
27
-
28
- async function getAllTsxFiles(dir: string): Promise<string[]> {
29
- debugFiles('Scanning directory for TSX files: %s', dir);
30
- let results: string[] = [];
31
-
32
- try {
33
- const entries = await fs.readdir(dir, { withFileTypes: true });
34
- debugFiles('Found %d entries in %s', entries.length, dir);
35
-
36
- for (const entry of entries) {
37
- const fullPath = path.join(dir, entry.name);
38
- if (entry.isDirectory()) {
39
- debugFiles('Entering subdirectory: %s', entry.name);
40
- const subResults = await getAllTsxFiles(fullPath);
41
- results = results.concat(subResults);
42
- debugFiles('Found %d TSX files in %s', subResults.length, entry.name);
43
- } else if (entry.isFile() && entry.name.endsWith('.tsx')) {
44
- debugFiles('Found TSX file: %s', entry.name);
45
- results.push(fullPath);
46
- }
47
- }
48
- } catch (error) {
49
- debugFiles('Error reading directory %s: %O', dir, error);
50
- }
51
-
52
- debugFiles('Total TSX files found in %s: %d', dir, results.length);
53
- return results;
54
- }
55
-
56
- function getComponentNameFromFile(filePath: string): string {
57
- debugComponents('Extracting component name from: %s', filePath);
58
- const file = path.basename(filePath, '.tsx');
59
- // Capitalize first letter
60
- const componentName = file.charAt(0).toUpperCase() + file.slice(1);
61
- debugComponents('Component name: %s', componentName);
62
- return componentName;
63
- }
64
-
65
- export async function generateDesignSystemMarkdown(inputDir: string, outputDir: string): Promise<void> {
66
- debugMarkdown('Generating design system markdown from: %s to: %s', inputDir, outputDir);
67
-
68
- const files = await getAllTsxFiles(inputDir);
69
- if (files.length === 0) {
70
- debugMarkdown('WARNING: No .tsx files found in input directory');
71
- console.warn('No .tsx files found in input directory.');
72
- return;
73
- }
74
-
75
- debugMarkdown('Processing %d TSX files', files.length);
76
- const componentNames = files.map(getComponentNameFromFile).sort();
77
- debugMarkdown('Found %d unique components', componentNames.length);
78
-
79
- let md = '# Design System\n\n## Components\n\n';
80
- for (const name of componentNames) {
81
- md += `- ${name}\n`;
82
- debugMarkdown('Added component to markdown: %s', name);
83
- }
84
-
85
- debugMarkdown('Creating output directory: %s', outputDir);
86
- await fs.mkdir(outputDir, { recursive: true });
87
-
88
- const outPath = path.join(outputDir, 'design-system.md');
89
- debugMarkdown('Writing markdown to: %s', outPath);
90
- await fs.writeFile(outPath, md);
91
- debugMarkdown('Markdown file written successfully, size: %d bytes', md.length);
92
- }
93
-
94
- export * from './commands/import-design-system';
95
- export type { FilterFunctionType } from './FigmaComponentsBuilder';
96
- export { CLI_MANIFEST } from './cli-manifest';
97
-
98
- async function copyFile(inputDir: string, outputDir: string, file: string): Promise<void> {
99
- const srcPath = path.join(inputDir, file);
100
- const destPath = path.join(outputDir, file);
101
- debugCopy('Attempting to copy file: %s from %s to %s', file, inputDir, outputDir);
102
-
103
- // Check if source file exists
104
- try {
105
- await fs.access(srcPath);
106
- debugCopy('Source file exists: %s', srcPath);
107
-
108
- debugCopy('Creating output directory: %s', outputDir);
109
- await fs.mkdir(outputDir, { recursive: true });
110
-
111
- await fs.copyFile(srcPath, destPath);
112
- debugCopy('Successfully copied %s to %s', file, destPath);
113
- } catch (error) {
114
- // File doesn't exist, skip copying
115
- debugCopy('File %s not found in %s, error: %O', file, inputDir, error);
116
- console.log(`File ${file} not found in ${inputDir}, skipping...`, error);
117
- }
118
- }
119
-
120
- export async function copyDesignSystemDocsAndUserPreferences(inputDir: string, outputDir: string): Promise<void> {
121
- debugCopy('Copying design system docs from %s to %s', inputDir, outputDir);
122
-
123
- // Ensure output directory exists
124
- debugCopy('Creating output directory: %s', outputDir);
125
- await fs.mkdir(outputDir, { recursive: true });
126
-
127
- // Try to copy existing files
128
- debugCopy('Copying design-system.md...');
129
- await copyFile(inputDir, outputDir, 'design-system.md');
130
-
131
- debugCopy('Copying design-system-principles.md...');
132
- await copyFile(inputDir, outputDir, 'design-system-principles.md');
133
-
134
- // If design-system.md doesn't exist in output, try to generate it from TSX files
135
- const designSystemPath = path.join(outputDir, 'design-system.md');
136
- debugCopy('Checking if design-system.md exists at: %s', designSystemPath);
137
-
138
- try {
139
- await fs.access(designSystemPath);
140
- debugCopy('design-system.md already exists');
141
- } catch {
142
- debugCopy('design-system.md does not exist, attempting to generate from TSX files');
143
- // File doesn't exist, try to generate from TSX files if inputDir exists
144
- try {
145
- await fs.access(inputDir);
146
- debugCopy('Input directory is accessible: %s', inputDir);
147
-
148
- const files = await getAllTsxFiles(inputDir);
149
- if (files.length > 0) {
150
- debugCopy('Found %d TSX files, generating design-system.md', files.length);
151
- await generateDesignSystemMarkdown(inputDir, outputDir);
152
- console.log(`Generated design-system.md from ${files.length} component files`);
153
- } else {
154
- debugCopy('No TSX files found in %s', inputDir);
155
- console.log(`No .tsx files found in ${inputDir} to generate design-system.md`);
156
- }
157
- } catch (error) {
158
- debugCopy('Input directory %s not accessible: %O', inputDir, error);
159
- console.log(`Input directory ${inputDir} not accessible`);
160
- }
161
- }
162
-
163
- debugCopy('Design system docs copy/generation complete');
164
- }
165
-
166
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
167
- async function getFigmaComponents(): Promise<{ name: string; description: string; thumbnail: string }[]> {
168
- debugFigma('Fetching Figma components from file: %s', process.env.FIGMA_FILE_ID);
169
- let components: { name: string; description: string; thumbnail: string }[] = [];
170
-
171
- try {
172
- debugFigma('Making API call to Figma...');
173
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
174
- const response = await api.getFileComponentSets({ file_key: process.env.FIGMA_FILE_ID });
175
- debugFigma('Figma API response received');
176
-
177
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
178
- components = response.meta.component_sets.map(
179
- (component: { name: string; description: string; thumbnail_url: string }) => {
180
- debugFigma('Processing component: %s', component.name);
181
- return {
182
- name: component.name,
183
- description: component.description,
184
- thumbnail: component.thumbnail_url,
185
- };
186
- },
187
- );
188
-
189
- debugFigma('Successfully fetched %d components from Figma', components.length);
190
- console.log('figma response: ', response);
191
- } catch (e) {
192
- debugFigma('ERROR: Failed to fetch Figma components: %O', e);
193
- console.error(e);
194
- }
195
-
196
- console.log(components.length);
197
- return components;
198
- }
199
-
200
- export function generateMarkdownFromComponents(
201
- components: { name: string; description: string; thumbnail: string }[],
202
- ): string {
203
- debugMarkdown('Generating markdown from %d components', components.length);
204
- let md = '# Design System\n\n## Components\n\n';
205
-
206
- if (components.length === 0) {
207
- debugMarkdown('WARNING: No components found to generate markdown');
208
- console.warn('No components found');
209
- }
210
-
211
- for (const [index, component] of components.entries()) {
212
- debugMarkdown('Processing component %d/%d: %s', index + 1, components.length, component.name);
213
- md += `### ${component.name}\nDescription: ${component.description}\nImage: ![${component.name} image](${component.thumbnail})\n\n`;
214
- debugMarkdown('Added component %s with description length: %d', component.name, component.description.length);
215
- }
216
-
217
- debugMarkdown('Generated markdown document, total size: %d bytes', md.length);
218
- return md;
219
- }
220
-
221
- export enum ImportStrategy {
222
- WITH_COMPONENTS = 'WITH_COMPONENTS',
223
- WITH_COMPONENT_SETS = 'WITH_COMPONENT_SETS',
224
- WITH_ALL_FIGMA_INSTANCES = 'WITH_ALL_FIGMA_INSTANCES',
225
- }
226
-
227
- export async function importDesignSystemComponentsFromFigma(
228
- outputDir: string,
229
- strategy: ImportStrategy = ImportStrategy.WITH_COMPONENT_SETS,
230
- filterFn?: FilterFunctionType,
231
- ): Promise<void> {
232
- debug('Starting Figma design system import');
233
- debug('Output directory: %s', outputDir);
234
- debug('Import strategy: %s', strategy);
235
- debug('Filter function provided: %s', filterFn ? 'yes' : 'no');
236
-
237
- const figmaComponentsBuilder = new FigmaComponentsBuilder();
238
- debugComponents('FigmaComponentsBuilder instance created');
239
-
240
- if (strategy === ImportStrategy.WITH_COMPONENTS) {
241
- debugComponents('Using strategy: WITH_COMPONENTS');
242
- await figmaComponentsBuilder.withFigmaComponents();
243
- } else if (strategy === ImportStrategy.WITH_COMPONENT_SETS) {
244
- debugComponents('Using strategy: WITH_COMPONENT_SETS');
245
- await figmaComponentsBuilder.withFigmaComponentSets();
246
- } else if (strategy === ImportStrategy.WITH_ALL_FIGMA_INSTANCES) {
247
- debugComponents('Using strategy: WITH_ALL_FIGMA_INSTANCES');
248
- await figmaComponentsBuilder.withAllFigmaInstanceNames();
249
- }
250
- debugComponents('Strategy applied successfully');
251
-
252
- // figmaComponentsBuilder.withFilteredNamesForMui();
253
- // figmaComponentsBuilder.withFilteredNamesForShadcn();
254
-
255
- if (filterFn) {
256
- debugComponents('Applying custom filter function');
257
- figmaComponentsBuilder.withFilter(filterFn);
258
- }
259
-
260
- debugComponents('Building Figma components...');
261
- const figmaComponents = figmaComponentsBuilder.build();
262
- debugComponents('Built %d Figma components', figmaComponents.length);
263
-
264
- console.log(figmaComponents.length);
265
-
266
- debugMarkdown('Generating markdown from Figma components');
267
- const generatedComponentsMDFile = generateMarkdownFromComponents(figmaComponents);
268
- debugMarkdown('Markdown generated, size: %d bytes', generatedComponentsMDFile.length);
269
-
270
- // const mdWithImageAnalysis = await generateTextWithAI(
271
- // `
272
- // Given this markdown file content:
273
- // ${generatedComponentsMDFile}
274
- //
275
- // ------ INSTRUCTIONS -------
276
- // !IMPORTANT: Only return with Markdown content, nothing else, I will be putting this straight in a .md file. Don't even start the file with \`\`\`markdown
277
- // For every component Image: Analyze the given image and add to the given component.
278
- // - add more content to the "Description:" part of the component.
279
- // - add "Hierarchy:" part under the component, returning the parts a component is build of. like [Button, Input]
280
- // `,
281
- // AIProvider.OpenAI,
282
- // { temperature: 0.2, maxTokens: 8000 },
283
- // );
284
- // await fs.mkdir(outputDir, { recursive: true });
285
-
286
- // Parse the outputDir to determine if it's a file path or directory
287
- const isFilePath = outputDir.endsWith('.md');
288
- const actualOutputDir = isFilePath ? path.dirname(outputDir) : outputDir;
289
- const fileName = isFilePath ? path.basename(outputDir) : 'design-system.md';
290
-
291
- debugFiles('Creating output directory: %s', actualOutputDir);
292
- await fs.mkdir(actualOutputDir, { recursive: true });
293
-
294
- const outPath = path.join(actualOutputDir, fileName);
295
- debugFiles('Writing markdown to: %s', outPath);
296
- await fs.writeFile(outPath, generatedComponentsMDFile);
297
- debugFiles('Design system markdown written successfully');
298
-
299
- debug('Figma design system import complete');
300
- }
301
-
302
- // Check if this file is being run directly
303
- if (process.argv[1] === __filename) {
304
- const [, , outputDir] = process.argv;
305
- if (!outputDir) {
306
- console.error('Usage: tsx src/index.ts <outputDir>');
307
- process.exit(1);
308
- }
309
- // generateDesignSystemMarkdown(inputDir, outputDir)
310
- // .then(() => {
311
- // console.log(`design-system.md generated in ${outputDir}`);
312
- // })
313
- // .catch((err) => {
314
- // console.error('Error generating design-system.md:', err);
315
- // process.exit(1);
316
- // });
317
- // copyDesignSystemDocsAndUserPreferences(inputDir, outputDir)
318
- // .then(() => {
319
- // console.log(`design-system.md copied to ${outputDir}`);
320
- // })
321
- // .catch((err) => {
322
- // console.error('Error copying design-system.md:', err);
323
- // process.exit(1);
324
- // });
325
- importDesignSystemComponentsFromFigma(outputDir)
326
- .then(() => {
327
- console.log(`design-system.md generated to ${outputDir}`);
328
- })
329
- .catch((err) => {
330
- console.error('Error generating design-system.md:', err);
331
- process.exit(1);
332
- });
333
- }
1
+ // Barrel exports
2
+ export { generateDesignSystemMarkdown } from './markdown-generator.js';
3
+ export { copyDesignSystemDocsAndUserPreferences } from './file-operations.js';
4
+ export { importDesignSystemComponentsFromFigma, ImportStrategy } from './figma-importer.js';
5
+ export type { FilterFunctionType } from './FigmaComponentsBuilder.js';
6
+
7
+ // Command exports
8
+ import importDesignSystemHandler from './commands/import-design-system.js';
9
+ export const COMMANDS = [importDesignSystemHandler];
@@ -0,0 +1,56 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs/promises';
3
+ import createDebug from 'debug';
4
+ import { getAllTsxFiles, getComponentNameFromFile } from './file-operations.js';
5
+
6
+ const debugMarkdown = createDebug('design-system-importer:markdown');
7
+
8
+ export async function generateDesignSystemMarkdown(inputDir: string, outputDir: string): Promise<void> {
9
+ debugMarkdown('Generating design system markdown from: %s to: %s', inputDir, outputDir);
10
+
11
+ const files = await getAllTsxFiles(inputDir);
12
+ if (files.length === 0) {
13
+ debugMarkdown('WARNING: No .tsx files found in input directory');
14
+ console.warn('No .tsx files found in input directory.');
15
+ return;
16
+ }
17
+
18
+ debugMarkdown('Processing %d TSX files', files.length);
19
+ const componentNames = files.map(getComponentNameFromFile).sort();
20
+ debugMarkdown('Found %d unique components', componentNames.length);
21
+
22
+ let md = '# Design System\n\n## Components\n\n';
23
+ for (const name of componentNames) {
24
+ md += `- ${name}\n`;
25
+ debugMarkdown('Added component to markdown: %s', name);
26
+ }
27
+
28
+ debugMarkdown('Creating output directory: %s', outputDir);
29
+ await fs.mkdir(outputDir, { recursive: true });
30
+
31
+ const outPath = path.join(outputDir, 'design-system.md');
32
+ debugMarkdown('Writing markdown to: %s', outPath);
33
+ await fs.writeFile(outPath, md);
34
+ debugMarkdown('Markdown file written successfully, size: %d bytes', md.length);
35
+ }
36
+
37
+ export function generateMarkdownFromComponents(
38
+ components: { name: string; description: string; thumbnail: string }[],
39
+ ): string {
40
+ debugMarkdown('Generating markdown from %d components', components.length);
41
+ let md = '# Design System\n\n## Components\n\n';
42
+
43
+ if (components.length === 0) {
44
+ debugMarkdown('WARNING: No components found to generate markdown');
45
+ console.warn('No components found');
46
+ }
47
+
48
+ for (const [index, component] of components.entries()) {
49
+ debugMarkdown('Processing component %d/%d: %s', index + 1, components.length, component.name);
50
+ md += `### ${component.name}\nDescription: ${component.description}\nImage: ![${component.name} image](${component.thumbnail})\n\n`;
51
+ debugMarkdown('Added component %s with description length: %d', component.name, component.description.length);
52
+ }
53
+
54
+ debugMarkdown('Generated markdown document, total size: %d bytes', md.length);
55
+ return md;
56
+ }