audit-telemetry-fields.mjs 852 B

123456789101112131415161718192021
  1. import { readFile } from "node:fs/promises";
  2. import { parseArgs } from "node:util";
  3. import { auditTelemetryFields } from "./lib/telemetry-field-contract.mjs";
  4. const { values } = parseArgs({
  5. options: {
  6. capture: { type: "string" },
  7. "artifact-dir": { type: "string" },
  8. "no-sync": { type: "boolean", default: false },
  9. },
  10. });
  11. if (!values.capture) throw new Error("需要 --capture <本轮 telemetry parity JSON>");
  12. const capture = JSON.parse(await readFile(values.capture, "utf8"));
  13. if (!Array.isArray(capture.eventReport)) throw new Error("capture.eventReport 必须是数组");
  14. const result = await auditTelemetryFields({
  15. records: capture.eventReport,
  16. artifactDir: values["artifact-dir"],
  17. sync: values["no-sync"] ? false : undefined,
  18. });
  19. console.log(JSON.stringify(result, null, 2));
  20. if (result.errors.length) process.exitCode = 1;