| 607 | } |
| 608 | } |
| 609 | function generateTelemetryCSV(output: TelemetryEntry[]) { |
| 610 | const entries: {}[] = []; |
| 611 | output.forEach((o) => { |
| 612 | if (o.propertyGroups.length === 0) { |
| 613 | // an event without any properties. |
| 614 | entries.push({ |
| 615 | eventName: o.name, |
| 616 | eventDescription: o.description, |
| 617 | eventConstant: o.constantName, |
| 618 | owner: o.gdpr.owner, |
| 619 | feature: Array.isArray(o.gdpr.feature) ? o.gdpr.feature.join(', ') : o.gdpr.feature || '', |
| 620 | tags: Array.isArray(o.gdpr.tags) ? o.gdpr.tags.join(', ') : o.gdpr.tags || '', |
| 621 | groupDescription: '', |
| 622 | propertyName: '', |
| 623 | propertyDescription: '', |
| 624 | propertyType: '', |
| 625 | propertyPossibleValues: '', |
| 626 | propertyIsNullable: '' |
| 627 | }); |
| 628 | } |
| 629 | o.propertyGroups.forEach((og) => { |
| 630 | const groupDescription = |
| 631 | typeof og.description === 'string' ? og.description : (og.description || []).join('\n'); |
| 632 | og.properties |
| 633 | .sort((a, b) => a.name.localeCompare(b.name)) |
| 634 | .forEach((p) => { |
| 635 | const description = Array.isArray(p.descriptions) |
| 636 | ? p.descriptions.join('\n') |
| 637 | : p.descriptions || ''; |
| 638 | const possibleValues = |
| 639 | Array.isArray(p.possibleValues) && p.possibleValues.length |
| 640 | ? p.possibleValues |
| 641 | .map((item) => `${item.value} ${item.comment ? `(${item.comment})` : ''}`) |
| 642 | .join('\n') |
| 643 | : ''; |
| 644 | |
| 645 | entries.push({ |
| 646 | eventName: o.name, |
| 647 | eventDescription: o.description, |
| 648 | eventConstant: o.constantName, |
| 649 | owner: o.gdpr.owner, |
| 650 | feature: Array.isArray(o.gdpr.feature) ? o.gdpr.feature.join(', ') : o.gdpr.feature || '', |
| 651 | tags: Array.isArray(o.gdpr.tags) ? o.gdpr.tags.join(', ') : o.gdpr.tags || '', |
| 652 | groupDescription, |
| 653 | propertyName: p.name, |
| 654 | propertyDescription: description, |
| 655 | propertyType: p.type, |
| 656 | propertyPossibleValues: possibleValues, |
| 657 | propertyIsNullable: p.isNullable |
| 658 | }); |
| 659 | }); |
| 660 | }); |
| 661 | }); |
| 662 | |
| 663 | const fields = Object.keys(entries[0]); |
| 664 | const parser = new Parser({ fields }); |
| 665 | const csv = parser.parse(entries); |
| 666 | fs.writeFileSync('./TELEMETRY.csv', csv); |