Skip to content

Commit

Permalink
feat: Add markdown output format, suitable for use in GitHub Job Summ…
Browse files Browse the repository at this point in the history
…aries
  • Loading branch information
lornajane committed Jan 16, 2024
1 parent 4efdc96 commit 011b34e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/cli/src/commands/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function printStatsJson(statsAccumulator: StatsAccumulator) {
process.stdout.write(JSON.stringify(json, null, 2));
}

function printStatsMarkdown(statsAccumulator: StatsAccumulator) {
let output = "";
for (const key of Object.keys(statsAccumulator)) {
output += "- " + statsAccumulator[key as StatsName].metric + ": " + statsAccumulator[key as StatsName].total + "\n";
}
process.stdout.write(output);
}

function printStats(statsAccumulator: StatsAccumulator, api: string, format: string) {
switch (format) {
case 'stylish':
Expand All @@ -55,6 +63,9 @@ function printStats(statsAccumulator: StatsAccumulator, api: string, format: str
case 'json':
printStatsJson(statsAccumulator);
break;
case 'markdown':
printStatsMarkdown(statsAccumulator);
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ yargs
},
format: {
description: 'Use a specific output format.',
choices: ['stylish', 'json'] as ReadonlyArray<OutputFormat>,
choices: ['stylish', 'json', 'markdown'] as ReadonlyArray<OutputFormat>,
default: 'stylish' as OutputFormat,
},
}),
Expand Down

0 comments on commit 011b34e

Please sign in to comment.