cli
cli copied to clipboard
format report output
User story
As a reader of the CLI reports I want to be able to easily consume the generated information. Formatting is key here. Even if many IDEs support a markdown viewer or auto-format JSON files, it still helps to be able to read the reports in a plain editor.
The current output of the markdown format is not formatted.
Acceptance criteria
- [ ] implement helper form text formatting by wrapping prettier
- [ ] accept the
content
to format and a optional argument for theformat
- [ ] accept the
- [ ] format all markdown formats accordingly
- [ ] ensure formatting is given over snapshot tests
Implementation details
Prettier wrapper:
// packages/utils/src/lib/formatting.ts
import { format, Options } from 'prettier';
export function formatText(
content: string,
parser: Options['parser'] = 'typescript'
) {
return format(content, {
parser
}).trim();
}
Markdown helper:
// packages/utils/src/lib/report/md/table.ts
import { formatText } from '../formatting';
export function tableHtml(data: (string | number)[][]): string {
if (data.length === 0) {
throw new Error("Data can't be empty");
}
const tableContent = data.map((arr, index) => {
if (index === 0) {
const headerRow = arr.map(s => `<th>${s}</th>`).join('');
return `<tr>${headerRow}</tr>`;
}
const row = arr.map(s => `<td>${s}</td>`).join('');
return `<tr>${row}</tr>`;
});
return formatText(`<table>${tableContent.join('')}</table>`;
}