|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Generate icon prompts for building blocks missing logo.png files. |
| 4 | +Parses README.md frontmatter and creates AI image generation prompts. |
| 5 | +""" |
| 6 | + |
| 7 | +import os |
| 8 | +import sys |
| 9 | +import yaml |
| 10 | +import json |
| 11 | +from pathlib import Path |
| 12 | + |
| 13 | +PLATFORM_COLORS = { |
| 14 | + "aws": { |
| 15 | + "primary": "#FF9900", |
| 16 | + "secondary": "#232F3E", |
| 17 | + "accent": "#7FBA00", |
| 18 | + "name": "AWS colors: orange (#FF9900), dark blue (#232F3E), and lime green (#7FBA00)" |
| 19 | + }, |
| 20 | + "azure": { |
| 21 | + "primary": "#0078D4", |
| 22 | + "secondary": "#00BCF2", |
| 23 | + "accent": "#50E6FF", |
| 24 | + "name": "Azure colors: blue (#0078D4), cyan (#00BCF2), and light blue (#50E6FF)" |
| 25 | + }, |
| 26 | + "aks": { |
| 27 | + "primary": "#326CE5", |
| 28 | + "secondary": "#0078D4", |
| 29 | + "accent": "#00BCF2", |
| 30 | + "name": "Kubernetes/Azure colors: blue (#326CE5), Azure blue (#0078D4), and cyan (#00BCF2)" |
| 31 | + }, |
| 32 | + "azuredevops": { |
| 33 | + "primary": "#0078D4", |
| 34 | + "secondary": "#00BCF2", |
| 35 | + "accent": "#005A9E", |
| 36 | + "name": "Azure DevOps colors: blue (#0078D4), teal (#00BCF2), and dark blue (#005A9E)" |
| 37 | + }, |
| 38 | + "gcp": { |
| 39 | + "primary": "#4285F4", |
| 40 | + "secondary": "#EA4335", |
| 41 | + "accent": "#FBBC04", |
| 42 | + "name": "Google colors: blue (#4285F4), red (#EA4335), yellow (#FBBC04), and green (#34A853)" |
| 43 | + }, |
| 44 | + "github": { |
| 45 | + "primary": "#6e5494", |
| 46 | + "secondary": "#24292e", |
| 47 | + "accent": "#8b5cf6", |
| 48 | + "name": "GitHub colors: purple (#6e5494), dark gray (#24292e), and bright purple (#8b5cf6)" |
| 49 | + }, |
| 50 | + "ionos": { |
| 51 | + "primary": "#003D7A", |
| 52 | + "secondary": "#FF6600", |
| 53 | + "accent": "#0096D6", |
| 54 | + "name": "IONOS colors: blue (#003D7A), orange (#FF6600), and light blue (#0096D6)" |
| 55 | + }, |
| 56 | + "kubernetes": { |
| 57 | + "primary": "#326CE5", |
| 58 | + "secondary": "#00D3E0", |
| 59 | + "accent": "#7AB8FF", |
| 60 | + "name": "Kubernetes colors: blue (#326CE5), cyan (#00D3E0), and light blue (#7AB8FF)" |
| 61 | + }, |
| 62 | + "sapbtp": { |
| 63 | + "primary": "#0070AD", |
| 64 | + "secondary": "#F0AB00", |
| 65 | + "accent": "#0078D4", |
| 66 | + "name": "SAP colors: blue (#0070AD), gold (#F0AB00), and light blue (#0078D4)" |
| 67 | + }, |
| 68 | + "stackit": { |
| 69 | + "primary": "#00A859", |
| 70 | + "secondary": "#007A3D", |
| 71 | + "accent": "#7FBA00", |
| 72 | + "name": "STACKIT colors: green (#00A859), dark green (#007A3D), and lime (#7FBA00)" |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | + |
| 77 | +def parse_readme_frontmatter(readme_path): |
| 78 | + """Extract YAML frontmatter from README.md""" |
| 79 | + with open(readme_path, 'r', encoding='utf-8') as f: |
| 80 | + content = f.read() |
| 81 | + |
| 82 | + if not content.startswith('---'): |
| 83 | + return None |
| 84 | + |
| 85 | + # Extract frontmatter between --- delimiters |
| 86 | + parts = content.split('---', 2) |
| 87 | + if len(parts) < 3: |
| 88 | + return None |
| 89 | + |
| 90 | + try: |
| 91 | + frontmatter = yaml.safe_load(parts[1]) |
| 92 | + return frontmatter |
| 93 | + except yaml.YAMLError: |
| 94 | + return None |
| 95 | + |
| 96 | + |
| 97 | +def get_platform_from_frontmatter(frontmatter): |
| 98 | + """Get the primary platform from supportedPlatforms list""" |
| 99 | + platforms = frontmatter.get('supportedPlatforms', []) |
| 100 | + if not platforms: |
| 101 | + return None |
| 102 | + return platforms[0] # Use first platform |
| 103 | + |
| 104 | + |
| 105 | +def generate_icon_prompt(name, platform, description): |
| 106 | + """Generate an AI image generation prompt for an icon""" |
| 107 | + platform_colors = PLATFORM_COLORS.get(platform) |
| 108 | + |
| 109 | + if not platform_colors: |
| 110 | + # Fallback to generic bright colors |
| 111 | + color_scheme = "bright, vibrant colors" |
| 112 | + else: |
| 113 | + color_scheme = platform_colors["name"] |
| 114 | + |
| 115 | + # Clean up description |
| 116 | + clean_description = description.strip().replace('\n', ' ') |
| 117 | + |
| 118 | + # Generate prompt |
| 119 | + prompt = f"""A flat design icon representing: {clean_description} |
| 120 | +
|
| 121 | +Use {color_scheme}. |
| 122 | +
|
| 123 | +Style requirements: |
| 124 | +- Simple geometric shapes |
| 125 | +- Clean lines |
| 126 | +- Modern flat style |
| 127 | +- 128x128px |
| 128 | +- White background |
| 129 | +- No shadows or gradients |
| 130 | +- Icon should be centered with appropriate padding |
| 131 | +
|
| 132 | +The icon should visually represent the building block's purpose while maintaining consistency with other {platform.upper()} building block icons.""" |
| 133 | + |
| 134 | + return prompt |
| 135 | + |
| 136 | + |
| 137 | +def find_missing_logos(modules_dir): |
| 138 | + """Find all buildingblock directories missing logo.png""" |
| 139 | + missing = [] |
| 140 | + |
| 141 | + for root, dirs, files in os.walk(modules_dir): |
| 142 | + if 'buildingblock' in root: |
| 143 | + buildingblock_path = Path(root) |
| 144 | + readme_path = buildingblock_path / 'README.md' |
| 145 | + logo_path = buildingblock_path / 'logo.png' |
| 146 | + |
| 147 | + if readme_path.exists() and not logo_path.exists(): |
| 148 | + frontmatter = parse_readme_frontmatter(readme_path) |
| 149 | + if frontmatter: |
| 150 | + platform = get_platform_from_frontmatter(frontmatter) |
| 151 | + name = frontmatter.get('name', 'Unknown') |
| 152 | + description = frontmatter.get('description', '') |
| 153 | + |
| 154 | + # Get relative path from modules directory |
| 155 | + rel_path = buildingblock_path.relative_to(modules_dir) |
| 156 | + |
| 157 | + missing.append({ |
| 158 | + 'path': str(rel_path), |
| 159 | + 'name': name, |
| 160 | + 'platform': platform, |
| 161 | + 'description': description, |
| 162 | + 'readme_path': str(readme_path), |
| 163 | + 'logo_path': str(logo_path) |
| 164 | + }) |
| 165 | + |
| 166 | + return missing |
| 167 | + |
| 168 | + |
| 169 | +def main(): |
| 170 | + # Get modules directory |
| 171 | + repo_root = Path(__file__).parent.parent.parent |
| 172 | + modules_dir = repo_root / 'modules' |
| 173 | + |
| 174 | + if not modules_dir.exists(): |
| 175 | + print(f"ERROR: Modules directory not found: {modules_dir}", file=sys.stderr) |
| 176 | + sys.exit(1) |
| 177 | + |
| 178 | + # Find missing logos |
| 179 | + missing_logos = find_missing_logos(modules_dir) |
| 180 | + |
| 181 | + if not missing_logos: |
| 182 | + print("✅ All building blocks have logos!") |
| 183 | + sys.exit(0) |
| 184 | + |
| 185 | + # Generate prompts for each missing logo |
| 186 | + results = [] |
| 187 | + for item in missing_logos: |
| 188 | + prompt = generate_icon_prompt( |
| 189 | + item['name'], |
| 190 | + item['platform'] or 'generic', |
| 191 | + item['description'] |
| 192 | + ) |
| 193 | + |
| 194 | + results.append({ |
| 195 | + 'name': item['name'], |
| 196 | + 'platform': item['platform'], |
| 197 | + 'path': item['path'], |
| 198 | + 'logo_path': item['logo_path'], |
| 199 | + 'prompt': prompt |
| 200 | + }) |
| 201 | + |
| 202 | + # Output as JSON for GitHub Action to consume |
| 203 | + print(json.dumps(results, indent=2)) |
| 204 | + |
| 205 | + return len(results) |
| 206 | + |
| 207 | + |
| 208 | +if __name__ == '__main__': |
| 209 | + sys.exit(main()) |
0 commit comments