@auto-engineer/design-system-importer 0.9.13 → 0.10.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.
- package/CHANGELOG.md +11 -0
- package/package.json +3 -3
- package/src/commands/import-design-system.ts +14 -13
- package/src/figma-importer.ts +25 -16
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"figma-api": "2.0.2-beta",
|
|
17
17
|
"tsx": "^3.12.7",
|
|
18
|
-
"@auto-engineer/message-bus": "0.
|
|
18
|
+
"@auto-engineer/message-bus": "0.10.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@auto-engineer/cli": "0.
|
|
21
|
+
"@auto-engineer/cli": "0.10.0"
|
|
22
22
|
},
|
|
23
|
-
"version": "0.
|
|
23
|
+
"version": "0.10.0",
|
|
24
24
|
"scripts": {
|
|
25
25
|
"start": "tsx src/index.ts",
|
|
26
26
|
"build": "tsc && tsx ../../scripts/fix-esm-imports.ts && cp -r src/utils/templates dist/src/utils/",
|
|
@@ -18,21 +18,24 @@ export type ImportDesignSystemCommand = Command<
|
|
|
18
18
|
>;
|
|
19
19
|
|
|
20
20
|
export type DesignSystemImportedEvent = Event<
|
|
21
|
-
'
|
|
21
|
+
'ImportDesignSystemCompleted',
|
|
22
22
|
{
|
|
23
23
|
outputDir: string;
|
|
24
24
|
}
|
|
25
25
|
>;
|
|
26
26
|
|
|
27
27
|
export type DesignSystemImportFailedEvent = Event<
|
|
28
|
-
'
|
|
28
|
+
'ImportDesignSystemFailed',
|
|
29
29
|
{
|
|
30
30
|
error: string;
|
|
31
31
|
outputDir: string;
|
|
32
32
|
}
|
|
33
33
|
>;
|
|
34
34
|
|
|
35
|
-
export const commandHandler = defineCommandHandler
|
|
35
|
+
export const commandHandler = defineCommandHandler<
|
|
36
|
+
ImportDesignSystemCommand,
|
|
37
|
+
(command: ImportDesignSystemCommand) => Promise<DesignSystemImportedEvent | DesignSystemImportFailedEvent>
|
|
38
|
+
>({
|
|
36
39
|
name: 'ImportDesignSystem',
|
|
37
40
|
alias: 'import:design-system',
|
|
38
41
|
description: 'Import Figma design system',
|
|
@@ -45,22 +48,20 @@ export const commandHandler = defineCommandHandler({
|
|
|
45
48
|
},
|
|
46
49
|
strategy: {
|
|
47
50
|
description: 'Import mode (e.g., WITH_COMPONENT_SETS)',
|
|
48
|
-
required: false,
|
|
49
51
|
},
|
|
50
52
|
filterPath: {
|
|
51
53
|
description: 'Optional filter file',
|
|
52
|
-
required: false,
|
|
53
54
|
},
|
|
54
55
|
},
|
|
55
56
|
examples: [
|
|
56
57
|
'$ auto import:design-system --output-dir=./.context --strategy=WITH_COMPONENT_SETS --filter-path=./shadcn-filter.ts',
|
|
57
58
|
],
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
events: ['ImportDesignSystemCompleted', 'ImportDesignSystemFailed'],
|
|
60
|
+
handle: async (command: Command): Promise<DesignSystemImportedEvent | DesignSystemImportFailedEvent> => {
|
|
61
|
+
const typedCommand = command as ImportDesignSystemCommand;
|
|
61
62
|
debug('CommandHandler executing for ImportDesignSystem');
|
|
62
|
-
const result = await handleImportDesignSystemCommandInternal(
|
|
63
|
-
if (result.type === '
|
|
63
|
+
const result = await handleImportDesignSystemCommandInternal(typedCommand);
|
|
64
|
+
if (result.type === 'ImportDesignSystemCompleted') {
|
|
64
65
|
debug('Command handler completed: success');
|
|
65
66
|
debugResult('Design system imported successfully to %s', result.data.outputDir);
|
|
66
67
|
} else {
|
|
@@ -100,7 +101,7 @@ async function loadFilterFunction(filterPath?: string): Promise<FilterFunctionTy
|
|
|
100
101
|
|
|
101
102
|
function createSuccessEvent(command: ImportDesignSystemCommand, outputDir: string): DesignSystemImportedEvent {
|
|
102
103
|
const successEvent: DesignSystemImportedEvent = {
|
|
103
|
-
type: '
|
|
104
|
+
type: 'ImportDesignSystemCompleted',
|
|
104
105
|
data: { outputDir },
|
|
105
106
|
timestamp: new Date(),
|
|
106
107
|
requestId: command.requestId,
|
|
@@ -121,13 +122,13 @@ function createFailureEvent(
|
|
|
121
122
|
debugResult('Error message: %s', errorMessage);
|
|
122
123
|
|
|
123
124
|
const failureEvent: DesignSystemImportFailedEvent = {
|
|
124
|
-
type: '
|
|
125
|
+
type: 'ImportDesignSystemFailed',
|
|
125
126
|
data: { error: errorMessage, outputDir },
|
|
126
127
|
timestamp: new Date(),
|
|
127
128
|
requestId: command.requestId,
|
|
128
129
|
correlationId: command.correlationId,
|
|
129
130
|
};
|
|
130
|
-
debugResult('Returning failure event:
|
|
131
|
+
debugResult('Returning failure event: ImportDesignSystemFailed');
|
|
131
132
|
debugResult(' Error: %s', errorMessage);
|
|
132
133
|
debugResult(' Output directory: %s', outputDir);
|
|
133
134
|
return failureEvent;
|
package/src/figma-importer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import createDebug from 'debug';
|
|
4
|
-
import {
|
|
4
|
+
import { type FilterFunctionType } from './FigmaComponentsBuilder.js';
|
|
5
5
|
import { generateMarkdownFromComponents } from './markdown-generator.js';
|
|
6
6
|
|
|
7
7
|
const debug = createDebug('design-system-importer');
|
|
@@ -25,31 +25,40 @@ export async function importDesignSystemComponentsFromFigma(
|
|
|
25
25
|
debug('Import strategy: %s', strategy);
|
|
26
26
|
debug('Filter function provided: %s', filterFn ? 'yes' : 'no');
|
|
27
27
|
|
|
28
|
-
const figmaComponentsBuilder = new FigmaComponentsBuilder();
|
|
29
|
-
debugComponents('FigmaComponentsBuilder instance created');
|
|
30
|
-
|
|
31
|
-
if (strategy === ImportStrategy.WITH_COMPONENTS) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} else if (strategy === ImportStrategy.WITH_COMPONENT_SETS) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} else if (strategy === ImportStrategy.WITH_ALL_FIGMA_INSTANCES) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
// const figmaComponentsBuilder = new FigmaComponentsBuilder();
|
|
29
|
+
// debugComponents('FigmaComponentsBuilder instance created');
|
|
30
|
+
|
|
31
|
+
// if (strategy === ImportStrategy.WITH_COMPONENTS) {
|
|
32
|
+
// debugComponents('Using strategy: WITH_COMPONENTS');
|
|
33
|
+
// await figmaComponentsBuilder.withFigmaComponents();
|
|
34
|
+
// } else if (strategy === ImportStrategy.WITH_COMPONENT_SETS) {
|
|
35
|
+
// debugComponents('Using strategy: WITH_COMPONENT_SETS');
|
|
36
|
+
// await figmaComponentsBuilder.withFigmaComponentSets();
|
|
37
|
+
// } else if (strategy === ImportStrategy.WITH_ALL_FIGMA_INSTANCES) {
|
|
38
|
+
// debugComponents('Using strategy: WITH_ALL_FIGMA_INSTANCES');
|
|
39
|
+
// await figmaComponentsBuilder.withAllFigmaInstanceNames();
|
|
40
|
+
// }
|
|
41
41
|
debugComponents('Strategy applied successfully');
|
|
42
42
|
|
|
43
43
|
// figmaComponentsBuilder.withFilteredNamesForMui();
|
|
44
44
|
// figmaComponentsBuilder.withFilteredNamesForShadcn();
|
|
45
|
+
let figmaComponents: { name: string; description: string; thumbnail: string }[] = [];
|
|
45
46
|
|
|
46
47
|
if (filterFn) {
|
|
47
48
|
debugComponents('Applying custom filter function');
|
|
48
|
-
figmaComponentsBuilder.withFilter(filterFn);
|
|
49
|
+
// figmaComponentsBuilder.withFilter(filterFn);
|
|
50
|
+
|
|
51
|
+
const absolutePath = path.resolve(outputDir, 'figma-file.json');
|
|
52
|
+
const rawFigmaFile = await fs.readFile(absolutePath, 'utf-8');
|
|
53
|
+
const parsedFile = JSON.parse(rawFigmaFile) as {
|
|
54
|
+
root: { name: string; description: string; thumbnail: string }[];
|
|
55
|
+
};
|
|
56
|
+
const nodes = parsedFile.root;
|
|
57
|
+
figmaComponents = filterFn(nodes);
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
debugComponents('Building Figma components...');
|
|
52
|
-
const figmaComponents = figmaComponentsBuilder.build();
|
|
61
|
+
// const figmaComponents = figmaComponentsBuilder.build();
|
|
53
62
|
debugComponents('Built %d Figma components', figmaComponents.length);
|
|
54
63
|
|
|
55
64
|
console.log(figmaComponents.length);
|