/**
 * Compares two files lighthouse outputs, listing changes between the numeric audits.
 */
import { readFileSync } from 'fs';

const firstFilePath = process.argv[2];
const secondFilePath = process.argv[3];

console.log(`\`${firstFilePath}\` -> \`${secondFilePath}\`\n\n`);
interface IOutput {
  audits: {
    [name: string]: {
      id: string;
      title: string;
      description: string;
      scoreDisplayMode: string;
      displayValue: string;
      rawValue: number;
    };
  };
}

const first: IOutput = JSON.parse(readFileSync(firstFilePath).toString());
const second: IOutput = JSON.parse(readFileSync(secondFilePath).toString());

for (const auditName in first.audits) {
  const firstAudit = first.audits[auditName];

  // only compare numeric audits
  if (firstAudit.scoreDisplayMode !== 'numeric') {
    continue;
  }
  const secondAudit = second.audits[auditName];
  const percentChange =
    ((secondAudit.rawValue - firstAudit.rawValue) / firstAudit.rawValue) * 100;

  if (isNaN(percentChange)) {
    continue;
  }
  console.log(
    `**${firstAudit.title}**\n* ${percentChange.toFixed(0)}% Δ\n* ${
      firstAudit.displayValue
    } -> ${secondAudit.displayValue}\n* ${firstAudit.description}\n`
  );
}

/**
 * Compares two files lighthouse outputs, listing changes between the numeric audits.
 *
 * Outputs in Markdown for easy posting in Github.
 */
import { readFileSync } from 'fs';

const firstFilePath = process.argv[2];
const secondFilePath = process.argv[3];

console.log(`\`${firstFilePath}\` -> \`${secondFilePath}\`\n\n`);
interface IOutput {
  audits: {
    [name: string]: {
      id: string;
      title: string;
      description: string;
      scoreDisplayMode: string;
      displayValue: string;
      rawValue: number;
    };
  };
}

const first: IOutput = JSON.parse(readFileSync(firstFilePath).toString());
const second: IOutput = JSON.parse(readFileSync(secondFilePath).toString());

for (const auditName in first.audits) {
  const firstAudit = first.audits[auditName];

  // only compare numeric audits
  if (firstAudit.scoreDisplayMode !== 'numeric') {
    continue;
  }
  const secondAudit = second.audits[auditName];
  const percentChange =
    ((secondAudit.rawValue - firstAudit.rawValue) / firstAudit.rawValue) * 100;

  if (isNaN(percentChange)) {
    continue;
  }
  console.log(
    `**${firstAudit.title}**\n* ${percentChange.toFixed(0)}% Δ\n* ${
      firstAudit.displayValue
    } -> ${secondAudit.displayValue}\n* ${firstAudit.description}\n`
  );
}

Add more docstring to module
Add more docstring to module
