GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — aicodingstack.io/scripts/refactor/export-vendors.ts at main · aicodingstack/aicodingstack.io Expand file tree/ Copy pathexport-vendors.tsMore file actions 384 lines (330 loc) · 10.6 KB / Copy pathexport-vendors.tsFile metadata and controls384 lines (330 loc) · 10.6 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 #!/usr/bin/env node /** * Export vendors from manifest files * This script extracts vendor information from ide/cli/extension/model/provider * manifest files and creates vendor files if they don't exist. */ import fs from 'node:fs/promises' import path from 'node:path' import { fileURLToPath } from 'node:url' const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) const ROOT_DIR = path.resolve(__dirname, '../..') const MANIFESTS_DIR = path.join(ROOT_DIR, 'manifests') const VENDORS_DIR = path.join(MANIFESTS_DIR, 'vendors') interface VendorData { name: string websiteUrl: string | null verified: boolean communityUrls: CommunityUrls | null translations: Record<string, { description?: string }> | null } interface CommunityUrls { linkedin: string | null twitter: string | null github: string | null youtube: string | null discord: string | null reddit: string | null blog: string | null } interface VendorObject { id: string name: string aliases?: string[] description: string translations: Record<string, { description?: string }> verified: boolean websiteUrl: string | null communityUrls: CommunityUrls } /** * Convert vendor name to vendor id * Rules: lowercase, replace spaces and dots with hyphens * @param vendorName - The vendor name * @returns The vendor id */ function vendorNameToId(vendorName: string): string { return vendorName .toLowerCase() .replace(/\s+/g, '-') .replace(/\./g, '-') .replace(/-+/g, '-') .replace(/^-|-$/g, '') } function normalizeVendorName(vendorName: string): string { return vendorName.trim().toLocaleLowerCase() } /** * Load and parse a JSON file * @param filePath - Path to the JSON file * @returns Parsed JSON object */ async function loadJSON(filePath: string): Promise<Record<string, unknown>> { const content = await fs.readFile(filePath, 'utf8') return JSON.parse(content) as Record<string, unknown> } /** * Check if a file exists * @param filePath - Path to the file * @returns True if file exists */ async function fileExists(filePath: string): Promise<boolean> { try { await fs.access(filePath) return true } catch { return false } } /** * Get all JSON files in a directory * @param dirPath - Directory path * @returns Array of JSON file paths */ async function getJsonFiles(dirPath: string): Promise<string[]> { try { const entries = await fs.readdir(dirPath, { withFileTypes: true }) const jsonFiles: string[] = [] for (const entry of entries) { if (entry.isFile() && entry.name.endsWith('.json')) { jsonFiles.push(path.join(dirPath, entry.name)) } } return jsonFiles.sort() } catch { return [] } } /** * Build a lookup from canonical vendor names and aliases to their stable IDs. * Conflicting identities are rejected so an alias can never point at two vendors. */ async function loadVendorIdentityIndex(): Promise<Map<string, string>> { const identityIndex = new Map<string, string>() for (const vendorFile of await getJsonFiles(VENDORS_DIR)) { const vendor = await loadJSON(vendorFile) const vendorId = vendor.id as string const names = [ vendor.name as string, ...(Array.isArray(vendor.aliases) ? (vendor.aliases as string[]) : []), ] for (const name of names) { const identity = normalizeVendorName(name) const existingVendorId = identityIndex.get(identity) if (existingVendorId && existingVendorId !== vendorId) { throw new Error( `Vendor identity "${name}" is claimed by both ${existingVendorId} and ${vendorId}` ) } identityIndex.set(identity, vendorId) } } return identityIndex } /** * Merge community URLs objects * Priority: existing value > new value (if existing is null/undefined, use new) * @param existing - Existing communityUrls object * @param newUrls - New communityUrls object * @returns Merged communityUrls object */ function mergeCommunityUrls( existing: CommunityUrls | null, newUrls: CommunityUrls | null ): CommunityUrls { const result: CommunityUrls = { linkedin: null, twitter: null, github: null, youtube: null, discord: null, reddit: null, blog: null, } // Start with existing values if (existing) { const keys = Object.keys(result) as Array<keyof CommunityUrls> for (const key of keys) { result[key] = existing[key] || null } } // Override with new values if existing is null if (newUrls) { const keys = Object.keys(result) as Array<keyof CommunityUrls> for (const key of keys) { if (!result[key] && newUrls[key]) { result[key] = newUrls[key] } } } return result } /** * Merge vendor information from multiple manifests * Priority: existing value > new value (if existing is null/undefined, use new) * @param existing - Existing vendor data * @param newData - New vendor data from manifest * @returns Merged vendor data */ function mergeVendorData(existing: VendorData, newData: VendorData): VendorData { const merged: VendorData = { ...existing } // Merge basic fields if (!merged.websiteUrl && newData.websiteUrl) { merged.websiteUrl = newData.websiteUrl } if (merged.verified === undefined && newData.verified !== undefined) { merged.verified = newData.verified } // Merge communityUrls merged.communityUrls = mergeCommunityUrls(merged.communityUrls, newData.communityUrls) // Merge translations if both exist if (newData.translations) { if (!merged.translations) { merged.translations = {} } // Merge translations descriptions for each locale for (const locale of Object.keys(newData.translations)) { if (!merged.translations[locale]) { merged.translations[locale] = {} } if (!merged.translations[locale].description && newData.translations[locale]?.description) { merged.translations[locale].description = newData.translations[locale].description } } } return merged } /** * Extract vendor information from a manifest file * @param manifest - The manifest object * @returns Extracted vendor data or null if no vendor field */ function extractVendorData(manifest: Record<string, unknown>): VendorData | null { if (!manifest.vendor) { return null } const vendorData: VendorData = { name: manifest.vendor as string, websiteUrl: (manifest.websiteUrl as string | null) || null, verified: (manifest.verified as boolean | undefined) !== undefined ? (manifest.verified as boolean) : false, communityUrls: (manifest.communityUrls as CommunityUrls | null) || null, translations: (manifest.translations as Record<string, { description?: string }> | null) || null, } return vendorData } /** * Create a vendor file from vendor data * @param vendorId - The vendor id * @param vendorData - The vendor data * @returns Complete vendor object */ function createVendorObject(vendorId: string, vendorData: VendorData): VendorObject { // Default description if not provided const defaultDescription = `${vendorData.name} is a vendor.` const vendor: VendorObject = { id: vendorId, name: vendorData.name, description: (vendorData as { description?: string }).description || defaultDescription, translations: vendorData.translations || {}, verified: vendorData.verified !== undefined ? vendorData.verified : false, websiteUrl: vendorData.websiteUrl || null, communityUrls: mergeCommunityUrls(null, vendorData.communityUrls), } return vendor } /** * Process a single manifest file and extract vendor information * @param manifestPath - Path to the manifest file * @param vendorsMap - Map of vendor id to vendor data */ async function processManifest( manifestPath: string, vendorsMap: Map<string, VendorData>, identityIndex: Map<string, string> ): Promise<void> { try { const manifest = await loadJSON(manifestPath) const vendorData = extractVendorData(manifest) if (!vendorData) { return } const vendorId = identityIndex.get(normalizeVendorName(vendorData.name)) ?? vendorNameToId(vendorData.name) // If vendor already exists in map, merge the data if (vendorsMap.has(vendorId)) { const existing = vendorsMap.get(vendorId)! vendorsMap.set(vendorId, mergeVendorData(existing, vendorData)) } else { vendorsMap.set(vendorId, vendorData) } } catch (error) { console.error(` ⚠️ Error processing ${manifestPath}:`, (error as Error).message) } } /** * Process all manifest files in a directory * @param categoryDir - Directory path * @param vendorsMap - Map of vendor id to vendor data */ async function processCategory( categoryDir: string, vendorsMap: Map<string, VendorData>, identityIndex: Map<string, string> ): Promise<void> { const jsonFiles = await getJsonFiles(categoryDir) if (jsonFiles.length === 0) { return } for (const jsonFile of jsonFiles) { await processManifest(jsonFile, vendorsMap, identityIndex) } } /** * Main function */ async function main(): Promise<void> { console.log('🔄 Exporting vendors from manifest files...\n') // Categories to process const categories = ['ides', 'clis', 'desktops', 'extensions', 'models', 'providers'] // Map to store vendor data (vendorId -> vendorData) const vendorsMap = new Map<string, VendorData>() const identityIndex = await loadVendorIdentityIndex() // Process all categories for (const category of categories) { const categoryDir = path.join(MANIFESTS_DIR, category) console.log(`📁 Processing ${category}/...`) await processCategory(categoryDir, vendorsMap, identityIndex) } console.log(`\n📊 Found ${vendorsMap.size} unique vendors\n`) // Create vendor files let createdCount = 0 let skippedCount = 0 for (const [vendorId, vendorData] of vendorsMap) { const vendorFilePath = path.join(VENDORS_DIR, `${vendorId}.json`) // Check if vendor file already exists if (await fileExists(vendorFilePath)) { console.log(`⏭️ Skipping ${vendorId} (already exists)`) skippedCount++ continue } // Create vendor object const vendor = createVendorObject(vendorId, vendorData) // Write vendor file const jsonContent = `${JSON.stringify(vendor, null, 2)}\n` await fs.writeFile(vendorFilePath, jsonContent, 'utf-8') console.log(`✅ Created ${vendorId}.json`) createdCount++ } console.log(`\n✨ Done!`) console.log(` Created: ${createdCount} vendors`) console.log(` Skipped: ${skippedCount} vendors`) } main().catch(error => { console.error('Fatal error:', error) process.exit(1) }) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |