()
| 92 | } |
| 93 | |
| 94 | export async function run(): Promise<void> { |
| 95 | console.log('🔍 Fetching PostHog event definitions and properties...\n'); |
| 96 | |
| 97 | try { |
| 98 | // Fetch all events |
| 99 | const events = await fetchAllEventDefinitions(); |
| 100 | console.log(`\n✅ Retrieved ${events.length} total events\n`); |
| 101 | |
| 102 | // Fetch properties for each event |
| 103 | const eventsWithProperties: EventWithProperties[] = []; |
| 104 | let processedCount = 0; |
| 105 | |
| 106 | for (const event of events) { |
| 107 | processedCount++; |
| 108 | console.log(`[${processedCount}/${events.length}] Fetching properties for: ${event.name}`); |
| 109 | |
| 110 | const properties = await fetchPropertiesForEvent(event.name); |
| 111 | eventsWithProperties.push({ |
| 112 | ...event, |
| 113 | properties, |
| 114 | }); |
| 115 | |
| 116 | console.log(` Found ${properties.length} properties`); |
| 117 | } |
| 118 | |
| 119 | // Save to file |
| 120 | const outputPath = join(process.cwd(), 'posthog-event-definitions.json'); |
| 121 | await writeFile(outputPath, JSON.stringify(eventsWithProperties, null, 2), 'utf-8'); |
| 122 | |
| 123 | console.log(`\n✅ Complete! Data saved to: ${outputPath}`); |
| 124 | console.log(`\nSummary:`); |
| 125 | console.log(` Total events: ${eventsWithProperties.length}`); |
| 126 | console.log( |
| 127 | ` Total properties: ${eventsWithProperties.reduce((sum, e) => sum + e.properties.length, 0)}` |
| 128 | ); |
| 129 | |
| 130 | // Print sample of events with most properties |
| 131 | console.log(`\nTop 10 events by property count:`); |
| 132 | const sortedByProperties = [...eventsWithProperties].sort( |
| 133 | (a, b) => b.properties.length - a.properties.length |
| 134 | ); |
| 135 | sortedByProperties.slice(0, 10).forEach((event, index) => { |
| 136 | console.log(` ${index + 1}. ${event.name} (${event.properties.length} properties)`); |
| 137 | }); |
| 138 | } catch (error) { |
| 139 | console.error('❌ Error:', error); |
| 140 | throw error; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | run().then(console.log, console.error); |
no test coverage detected