#!/usr/bin/env node const fs = require('fs') const path = require('path') // Paths const peopleComponentsDir = path.join(__dirname, '../src/components/people') const peopleDataFile = path.join(__dirname, '../src/lib/peopleData.ts') // Function to get all People_*.tsx files function getPeopleComponents() { if (!fs.existsSync(peopleComponentsDir)) { console.log('People components directory not found') return [] } const files = fs.readdirSync(peopleComponentsDir) return files .filter(file => file.startsWith('People_') && file.endsWith('.tsx')) .map(file => { const componentName = file.replace('.tsx', '') const importName = componentName.toLowerCase().replace('people_', '') return { fileName: file, componentName, importName, importPath: `@/components/people/${componentName}` } }) } // Function to generate the peopleData.ts content function generatePeopleDataContent(components) { const imports = components .map(comp => `import { data as ${comp.importName}Data } from '${comp.importPath}'`) .join('\n') const dynamicImports = components .map(comp => ` () => import('${comp.importPath}'),`) .join('\n') const syncDataPush = components .map(comp => ` try { allPeopleData.push(...${comp.importName}Data) } catch (error) { console.error('Error loading ${comp.importName} data:', error) }`) .join('\n') return `// This file is auto-generated by scripts/generate-people-data.js // When new people components are added, run: npm run generate-people-data export interface PersonData { name: string role: string imageUrl: string xUrl: string linkedinUrl: string } // Function to dynamically get all people data export async function getAllPeopleData(): Promise { const allPeopleData: PersonData[] = [] // Auto-generated list of all people components const peopleComponents = [ ${dynamicImports} ] for (const importComponent of peopleComponents) { try { const module = await importComponent() if (module.data && Array.isArray(module.data)) { allPeopleData.push(...module.data) } } catch (error) { console.error('Error loading people data:', error) } } return allPeopleData } // Synchronous version using static imports for immediate data access ${imports} export function getAllPeopleDataSync(): PersonData[] { const allPeopleData: PersonData[] = [] ${syncDataPush} return allPeopleData } ` } // Main function function main() { console.log('šŸ” Scanning for people components...') const components = getPeopleComponents() if (components.length === 0) { console.log('āŒ No people components found') return } console.log(`āœ… Found ${components.length} people component(s):`) components.forEach(comp => { console.log(` - ${comp.componentName}`) }) console.log('šŸ“ Generating peopleData.ts...') const content = generatePeopleDataContent(components) fs.writeFileSync(peopleDataFile, content, 'utf8') console.log('āœ… Successfully updated src/lib/peopleData.ts') console.log('\nšŸŽ‰ All people components will now automatically appear on the people page!') } // Run the script if (require.main === module) { main() } module.exports = { main, getPeopleComponents, generatePeopleDataContent }