| 674 | `; |
| 675 | |
| 676 | function generateTelemetryGdpr(output: TelemetryEntry[]) { |
| 677 | const file = './src/gdpr.ts'; |
| 678 | fs.writeFileSync(file, ''); |
| 679 | fs.appendFileSync(file, gdprHeader); |
| 680 | const gdpr = '__GDPR__FRAGMENT__'; |
| 681 | fs.appendFileSync(file, `/* ${gdpr}\n`); |
| 682 | fs.appendFileSync(file, ` "F1" : {\n`); |
| 683 | const commonFields = [' "${include}": [']; |
| 684 | const fieldListForFile: string[] = []; |
| 685 | Object.keys(CommonProperties).forEach((key) => { |
| 686 | const entry = (CommonProperties as any)[key] as IPropertyDataMeasurement | IPropertyDataNonMeasurement; |
| 687 | const isMeasurement = entry.isMeasurement === true; |
| 688 | const jsDocComment = commonPropertyComments.get(key) || ''; |
| 689 | let comment = (entry.comment || '').split(/\r?\n/).join(' ').trim(); |
| 690 | comment = `${comment}${comment.length === 0 || comment.endsWith('.') ? '' : '. '}${jsDocComment}`.trim(); |
| 691 | if (!comment) { |
| 692 | console.error( |
| 693 | `No comments for common property ${key}, Update CommonPropertyAndMeasureTypeNames in telemetry.ts` |
| 694 | ); |
| 695 | } |
| 696 | |
| 697 | // Do not include `__GDPR__` in the string with JSON comments, else telemetry tool treats this as a valid GDPR annotation. |
| 698 | const json = { |
| 699 | classification: 'SystemMetaData', |
| 700 | purpose: 'FeatureInsight', |
| 701 | isMeasurement: isMeasurement, |
| 702 | comment: comment |
| 703 | }; |
| 704 | fieldListForFile.push(` "${key}": ${JSON.stringify(json)}`); |
| 705 | }); |
| 706 | commonFields.push(' "${F1}"\n'); |
| 707 | commonFields.push(' ]'); |
| 708 | fs.appendFileSync(file, `${fieldListForFile.join(',\n')}\n`); |
| 709 | fs.appendFileSync(file, ` }\n`); |
| 710 | fs.appendFileSync(file, ` */\n`); |
| 711 | fs.appendFileSync(file, '\n'); |
| 712 | |
| 713 | output.forEach((item, index) => { |
| 714 | // Do not include `__GDPR__` in the string with JSON comments, else telemetry tool treats this as a valid GDPR annotation. |
| 715 | const gdpr = '__GDPR__'; |
| 716 | const header = [ |
| 717 | `// (${index + 1}). ${item.constantName} (${item.name})`, |
| 718 | ...(item.description.trim().length |
| 719 | ? item.description.split(/\r?\n/).map((c) => (c.length ? `// ${c}` : '//')) |
| 720 | : []), |
| 721 | `/* ${gdpr}`, |
| 722 | ` "${item.name}" : {` |
| 723 | ]; |
| 724 | const footer = [' }', ' */', '', '']; |
| 725 | const properties: Record<string, IPropertyDataNonMeasurement> = |
| 726 | 'properties' in item.gdpr ? (item.gdpr['properties'] as Record<string, IPropertyDataNonMeasurement>) : {}; |
| 727 | const measures: Record<string, IPropertyDataMeasurement> = |
| 728 | 'measures' in item.gdpr ? (item.gdpr['measures'] as Record<string, IPropertyDataMeasurement>) : {}; |
| 729 | const entries: string[] = []; |
| 730 | Object.keys(properties).forEach((key) => { |
| 731 | if (key in CommonProperties) { |
| 732 | return; |
| 733 | } |