Skip to content

feat(icon-generator): configured icon generator #11685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ lerna-debug.log
# For vim
*.swp
.yarn
yarn.lock
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,3 @@ The process for revoking someone's maintainer status is a discussion limited to
[1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct/
[2]: mailto:[email protected]
[3]: https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#type

4 changes: 3 additions & 1 deletion packages/react-core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
/deprecated
/components
/layouts
/helpers
/helpers

.env
112 changes: 112 additions & 0 deletions packages/react-core/codeConnect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# PatternFly React Icon Generation System

## Overview

The PatternFly React icon generation system automates the process of creating and managing icon components, including generation, Figma connections, and consistent integration.

## Components

### 1. Icon Data Source (`iconsData.json`)
Defines the metadata for each icon in the library.

#### JSON Structure
```json
[
{
"iconName": "angle-down",
"fileName": "angle-down-icon",
"reactName": "AngleDownIcon",
"url": "Optional Figma design URL",
"svgPath": "SVG path data for the icon"
}
]
```

### 2. Configuration (`config.json`)
Manages global settings for icon generation.

#### Configuration Options
- `figmaBaseUrl`: Base URL for Figma design references
- `defaultNodeId`: Fallback Figma node identifier

### 3. Icon Template (`iconTemplate.txt`)
Provides a consistent template for generating individual icon components.

### 4. Scripts

#### `iconConnector.mjs`
Generates Figma connection files for icons.

#### `iconGenerator.mjs`
Creates individual icon component files and manages icon-related artifacts.

## Workflow

### 1. Prepare Icon Data
Create or update `iconsData.json` with icon specifications.

### 2. Configuration
Customize `config.json` with project-specific settings.

### 3. Generation Commands

#### Generate Icons
```bash
# Generate icon components and Figma connections
npm run figma:icons:generate
```

#### Publish to Figma
```bash
# Publish generated icon connections
npm run figma:icons:publish
```

## Best Practices

- Keep `iconsData.json` updated with the latest icon information
- Ensure SVG paths are clean and optimized
- Maintain consistent naming conventions
- Validate icon designs in Figma before generation

## Troubleshooting

### Common Issues
- **Missing Configuration**: Verify `config.json` exists and is correctly formatted
- **SVG Path Errors**: Check SVG path syntax and completeness
- **Naming Conflicts**: Ensure unique `reactName` for each icon

### Logging
The system uses a comprehensive logging utility that provides:
- Timestamped logs
- Contextual information
- Color-coded output for different log levels

## Extensibility

The modular design allows easy extension:
- Add new icons by updating `iconsData.json`
- Customize icon templates
- Modify configuration as project needs evolve

## Contributing

1. Update `iconsData.json` with new icon specifications
2. Validate SVG paths and icon designs
3. Run generation scripts
4. Review generated components
5. Commit changes

## Dependencies

- Node.js
- Figma Code Connect
- PatternFly React ecosystem

## License

[Insert appropriate license information]

## Support

For issues or questions, please file a GitHub issue in the PatternFly React repository.
4 changes: 4 additions & 0 deletions packages/react-core/codeConnect/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"figmaBaseUrl": "https://www.figma.com/design/VMEX8Xg2nzhBX8rfBx53jp/branch/H3LonYnwH26v9zNEa2SXFk/PatternFly-6%3A-Components",
"defaultNodeId": "1-196"
}
1 change: 1 addition & 0 deletions packages/react-core/codeConnect/data/iconsData.json

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions packages/react-core/codeConnect/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Icon Generation Technical Documentation

## System Architecture

### Components
- `iconConnector.mjs`: Manages Figma connections
- `iconGenerator.mjs`: Generates icon components
- `config.mjs`: Centralized configuration management
- `logger.mjs`: Logging utility

### Configuration Resolution
1. Finds repository root using `findRepoRoot()`
2. Loads configuration from `config.json`
3. Provides fallback default configuration

## Configuration Utility (`config.mjs`)

### Key Functions

#### `findRepoRoot()`
- Traverses directory tree to locate repository root
- Identifies root by presence of `.git` or `package.json`
- Fallback to current directory if no root found

#### `loadConfig(configPath)`
- Reads configuration from specified path
- Merges with default configuration
- Handles missing or invalid configuration files

#### `getIconConfig()`
- Resolves paths relative to repository root
- Combines configuration with path resolutions
- Returns comprehensive configuration object

### Configuration Properties
- `iconsDataPath`: Path to icon metadata
- `iconTemplatePath`: Path to icon component template
- `iconsGeneratedDir`: Output directory for generated icons
- `iconsFigmaDir`: Directory for Figma connection files
- `figmaBaseUrl`: Base URL for Figma design references
- `defaultNodeId`: Fallback Figma node identifier

## Logging Utility (`logger.mjs`)

### Log Levels
- `success`: Green, indicates successful operations
- `info`: Informational messages
- `warn`: Yellow, highlights potential issues
- `error`: Red, indicates critical failures

### Log Context
Each log method supports:
- Source identification
- Contextual metadata
- Detailed error information

## Icon Generation Process

### Icon Data Parsing
1. Read `iconsData.json`
2. Validate icon metadata
3. Fallback to example data if parsing fails

### Component Generation
1. Load icon template
2. Replace placeholders with icon-specific data
3. Generate individual `.tsx` files

### Figma Connection
1. Create Figma connection file
2. Map icons to Figma design references
3. Generate example usage snippets

## Error Handling

### Configuration Errors
- Fallback to default configuration
- Detailed logging of configuration issues

### File Generation Errors
- Comprehensive error reporting
- Graceful degradation with example data
- Detailed context logging

## Performance Considerations
- Minimal file system operations
- Efficient path resolution
- Cached configuration loading

## Security Notes
- No direct external dependencies in core logic
- Minimal file system interactions
- Configurable and extensible design

## Extensibility Points
- Custom icon template
- Configurable path resolutions
- Pluggable logging mechanism

## Debugging

### Verbose Mode
```bash
npm run figma:icons:generate -- --verbose
```

### Troubleshooting Flags
- `--debug`: Enables detailed debugging output
- `--dry-run`: Simulates generation without file writes

## Future Improvements
- Add icon validation
- Support for multiple icon sources
- Enhanced template customization
- Automated design system sync
Loading
Loading