|
| 1 | +# Icon Generation Technical Documentation |
| 2 | + |
| 3 | +## System Architecture |
| 4 | + |
| 5 | +### Components |
| 6 | +- `iconConnector.mjs`: Manages Figma connections |
| 7 | +- `iconGenerator.mjs`: Generates icon components |
| 8 | +- `config.mjs`: Centralized configuration management |
| 9 | +- `logger.mjs`: Logging utility |
| 10 | + |
| 11 | +### Configuration Resolution |
| 12 | +1. Finds repository root using `findRepoRoot()` |
| 13 | +2. Loads configuration from `config.json` |
| 14 | +3. Provides fallback default configuration |
| 15 | + |
| 16 | +## Configuration Utility (`config.mjs`) |
| 17 | + |
| 18 | +### Key Functions |
| 19 | + |
| 20 | +#### `findRepoRoot()` |
| 21 | +- Traverses directory tree to locate repository root |
| 22 | +- Identifies root by presence of `.git` or `package.json` |
| 23 | +- Fallback to current directory if no root found |
| 24 | + |
| 25 | +#### `loadConfig(configPath)` |
| 26 | +- Reads configuration from specified path |
| 27 | +- Merges with default configuration |
| 28 | +- Handles missing or invalid configuration files |
| 29 | + |
| 30 | +#### `getIconConfig()` |
| 31 | +- Resolves paths relative to repository root |
| 32 | +- Combines configuration with path resolutions |
| 33 | +- Returns comprehensive configuration object |
| 34 | + |
| 35 | +### Configuration Properties |
| 36 | +- `iconsDataPath`: Path to icon metadata |
| 37 | +- `iconTemplatePath`: Path to icon component template |
| 38 | +- `iconsGeneratedDir`: Output directory for generated icons |
| 39 | +- `iconsFigmaDir`: Directory for Figma connection files |
| 40 | +- `figmaBaseUrl`: Base URL for Figma design references |
| 41 | +- `defaultNodeId`: Fallback Figma node identifier |
| 42 | + |
| 43 | +## Logging Utility (`logger.mjs`) |
| 44 | + |
| 45 | +### Log Levels |
| 46 | +- `success`: Green, indicates successful operations |
| 47 | +- `info`: Informational messages |
| 48 | +- `warn`: Yellow, highlights potential issues |
| 49 | +- `error`: Red, indicates critical failures |
| 50 | + |
| 51 | +### Log Context |
| 52 | +Each log method supports: |
| 53 | +- Source identification |
| 54 | +- Contextual metadata |
| 55 | +- Detailed error information |
| 56 | + |
| 57 | +## Icon Generation Process |
| 58 | + |
| 59 | +### Icon Data Parsing |
| 60 | +1. Read `iconsData.json` |
| 61 | +2. Validate icon metadata |
| 62 | +3. Fallback to example data if parsing fails |
| 63 | + |
| 64 | +### Component Generation |
| 65 | +1. Load icon template |
| 66 | +2. Replace placeholders with icon-specific data |
| 67 | +3. Generate individual `.tsx` files |
| 68 | + |
| 69 | +### Figma Connection |
| 70 | +1. Create Figma connection file |
| 71 | +2. Map icons to Figma design references |
| 72 | +3. Generate example usage snippets |
| 73 | + |
| 74 | +## Error Handling |
| 75 | + |
| 76 | +### Configuration Errors |
| 77 | +- Fallback to default configuration |
| 78 | +- Detailed logging of configuration issues |
| 79 | + |
| 80 | +### File Generation Errors |
| 81 | +- Comprehensive error reporting |
| 82 | +- Graceful degradation with example data |
| 83 | +- Detailed context logging |
| 84 | + |
| 85 | +## Performance Considerations |
| 86 | +- Minimal file system operations |
| 87 | +- Efficient path resolution |
| 88 | +- Cached configuration loading |
| 89 | + |
| 90 | +## Security Notes |
| 91 | +- No direct external dependencies in core logic |
| 92 | +- Minimal file system interactions |
| 93 | +- Configurable and extensible design |
| 94 | + |
| 95 | +## Extensibility Points |
| 96 | +- Custom icon template |
| 97 | +- Configurable path resolutions |
| 98 | +- Pluggable logging mechanism |
| 99 | + |
| 100 | +## Debugging |
| 101 | + |
| 102 | +### Verbose Mode |
| 103 | +```bash |
| 104 | +npm run figma:icons:generate -- --verbose |
| 105 | +``` |
| 106 | + |
| 107 | +### Troubleshooting Flags |
| 108 | +- `--debug`: Enables detailed debugging output |
| 109 | +- `--dry-run`: Simulates generation without file writes |
| 110 | + |
| 111 | +## Future Improvements |
| 112 | +- Add icon validation |
| 113 | +- Support for multiple icon sources |
| 114 | +- Enhanced template customization |
| 115 | +- Automated design system sync |
0 commit comments