/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
scripts/cli/analytics/generateMarkdown.mts
86 строк
2 KB
Dominik Prokop
Analytics: silent option for reportInteraction and defineFeatureEvents (#123905)
06 май 2026, 10:50
Не верифицирован
06 май 2026, 10:50
5a961aa
Код
Авторство
О чём код?
import prettier from 'prettier'; import type { EventData } from './types.mts'; const makeMarkdownTable = (properties: Array<Record<string, string | undefined>>): string => { if (properties.length === 0) { return ''; } const keys = Object.keys(properties[0]); const header = `| ${keys.join(' | ')} |`; const border = `| ${keys.map((header) => '-'.padEnd(header.length, '-')).join(' | ')} |`; const rows = properties.map((property) => { const columns = keys.map((key) => { const value = property[key] ?? ''; return String(value).replace(/\\/g, '\\\\').replace(/\|/g, '\\|'); }); return '| ' + columns.join(' | ') + ' |'; }); return [header, border, ...rows].join('\n'); }; export const formatEventAsMarkdown = (event: EventData): string => { const preparedProperties = event.properties?.map((property) => { return { name: property.name, type: '`' + property.type + '`', description: property.description, }; }) ?? []; const propertiesTable = event.properties && event.properties.length > 0 ? makeMarkdownTable(preparedProperties) : ''; const markdownRows = [ `#### \`${event.fullEventName}\``, `**Description**: ${event.description}`, event.owner ? `**Owner:** ${event.owner}` : undefined, ...(event.properties ? [`**Properties**:`, propertiesTable] : []), ].filter(Boolean); return markdownRows.join('\n\n'); }; export async function formatEventsAsMarkdown(events: EventData[]): Promise<string> { // Silent events are subscriber-only and never forwarded to analytics backends, // so they don't belong in a Rudderstack-facing registry. The silent flag is // still preserved on EventData for non-markdown consumers (e.g. JSON output). const reportableEvents = events.filter((event) => !event.silent); const byFeature: Record<string, EventData[]> = {}; for (const event of reportableEvents) { const feature = event.feature; byFeature[feature] = byFeature[feature] ?? []; byFeature[feature].push(event); } const markdownPerFeature = Object.entries(byFeature) .map(([feature, events]) => { const markdownPerEvent = events.map(formatEventAsMarkdown).join('\n'); return ` ### ${feature} ${markdownPerEvent} `; }) .join('\n'); const markdown = ` # Analytics report This report contains all the analytics events that are defined in the project. ## Events ${markdownPerFeature} `; return prettier.format(markdown, { parser: 'markdown' }); }