Skip to content

Commit b3ad270

Browse files
authored
feat: generator handle svg (#20)
1 parent a94dacb commit b3ad270

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

src/markdown/component-workflow.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,88 @@ AI must analyze component design and infer:
155155
- State definitions
156156
- Slot specifications
157157
- Component structure
158+
- Image assets and their paths
158159
3. If user identifies issues:
159160
- Collect all feedback
160161
- Make required modifications to the architecture document
161162
- Present updated document for review
162163
4. Repeat review cycle until user explicitly approves the document
163164
5. Only proceed to Test Generation phase after user confirmation
164165

166+
#### Image Resource Handling
167+
168+
**CRITICAL STEP**: After user confirmation of the architecture document, and before proceeding to Test Generation:
169+
170+
1. **Resource Inventory and Path Documentation**:
171+
172+
- The architecture document must include an "Image Resources" section that clearly lists all necessary resources in a table format:
173+
174+
```markdown
175+
## Image Resources
176+
177+
### Resource List and Paths
178+
179+
| Icon Description | Original Path | Target Path | Icon Color Control |
180+
| ---------------- | ------------------------- | ------------------------------------------------------- | ---------------------------------------------------- |
181+
| Close Icon | `/original/path/icon.svg` | `src/components/${componentName}/images/icon-close.svg` | Dynamically controlled, defaults to match text color |
182+
| Other Icon | ... | ... | ... |
183+
```
184+
185+
2. **Copy Images**:
186+
187+
- Copy all necessary image resources listed in the architecture document to the component-specific directory.
188+
- Use semantic filenames such as `icon-close.svg`, `icon-success.svg`, `bg-header.png`, etc., ensuring the names clearly indicate the purpose of each image.
189+
- The target path must be `src/components/${componentName}/images/`. Create this directory if it doesn't exist.
190+
- Example:
191+
```bash
192+
mkdir -p src/components/${componentName}/images
193+
cp /original/path/close-icon.svg src/components/${componentName}/images/icon-close.svg
194+
```
195+
196+
3. **SVG Image Import and Color Specification**:
197+
198+
- The architecture document must clearly specify the import method and color control approach for SVG icons.
199+
- SVGs must be imported using the following method to ensure dynamic color control:
200+
201+
```typescript
202+
import CloseIcon from "./images/icon-close.svg?raw"; // ?raw ensures it's imported as a string
203+
```
204+
205+
- The architecture document must include code examples for SVG usage and color control:
206+
207+
````markdown
208+
### Icon Import and Usage Method
209+
210+
```typescript
211+
// In ${componentName}.vue, import icons
212+
import CloseIcon from "./images/icon-close.svg?raw";
213+
import SuccessIcon from "./images/icon-success.svg?raw";
214+
```
215+
````
216+
217+
Using SVGs in templates and controlling their color:
218+
219+
```html
220+
<template>
221+
<div class="icon-container" v-html="CloseIcon"></div>
222+
</template>
223+
224+
<style scoped>
225+
.icon-container svg {
226+
fill: v-bind("dynamicColorVariable"); /* Dynamically bind color */
227+
}
228+
/* Or use CSS variables to control color */
229+
.icon-container svg {
230+
fill: var(--icon-color, currentColor);
231+
}
232+
</style>
233+
```
234+
235+
- For each SVG icon, the architecture document must clearly specify:
236+
1. Default color
237+
2. Whether the color is fixed or needs to be dynamically controlled
238+
3. Color variations in different states
239+
165240
### 2. Test Generation
166241
167242
**Input**: Approved architecture document

src/tools/get-component-workflow.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ export class GetComponentWorkflowTool extends BaseTool {
5858
(layer.path ?? []).forEach((svgPath: string, index: number) => {
5959
const filePath = `${imageDir}/${id}-${index}.svg`;
6060
if (!fs.existsSync(filePath)) {
61-
fs.writeFileSync(filePath, svgPath);
61+
fs.writeFileSync(
62+
filePath,
63+
`<svg width="100%" height="100%" viewBox="0 0 16 16"xmlns="http://www.w3.org/2000/svg">
64+
<path d="${svgPath}" fill="currentColor"/>
65+
</svg>`
66+
);
6267
}
6368
layer.imageUrls.push(filePath);
6469
});
@@ -91,7 +96,7 @@ export class GetComponentWorkflowTool extends BaseTool {
9196
},
9297
message: "Component development files successfully created",
9398
rules: [
94-
`Follow the component workflow process defined in file://${workflowFilePath} for structured development.`,
99+
`Follow the component workflow process defined in file://${workflowFilePath} for structured development. This workflow contains a lot of content, you'll need to read it in multiple sessions.`,
95100
`Implement the component according to the specifications in file://${componentJsonDir}, ensuring all properties and states are properly handled.`,
96101
],
97102
}),

0 commit comments

Comments
 (0)