From a17b865119800e8647d711e5173977472621b713 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 28 Dec 2024 16:41:10 +0100 Subject: [PATCH] repo-tools: run prettier on sql reports Signed-off-by: Patrik Oldsberg --- .../sql-reports/runSqlExtraction.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/repo-tools/src/commands/api-reports/sql-reports/runSqlExtraction.ts b/packages/repo-tools/src/commands/api-reports/sql-reports/runSqlExtraction.ts index ac29f1f027..7fa44fe046 100644 --- a/packages/repo-tools/src/commands/api-reports/sql-reports/runSqlExtraction.ts +++ b/packages/repo-tools/src/commands/api-reports/sql-reports/runSqlExtraction.ts @@ -184,11 +184,13 @@ async function runSingleSqlExtraction( } } - const report = generateSqlReport({ - reportName, - failedDownMigration, - schemaInfo, - }); + const report = prettyReport( + generateSqlReport({ + reportName, + failedDownMigration, + schemaInfo, + }), + ); const reportPath = cliPaths.resolveTargetRoot( targetDir, @@ -225,3 +227,17 @@ async function runSingleSqlExtraction( } } } + +function prettyReport(content: string): string { + try { + const prettier = require('prettier') as typeof import('prettier'); + + const config = prettier.resolveConfig.sync(cliPaths.targetRoot) ?? {}; + return prettier.format(content, { + ...config, + parser: 'markdown', + }); + } catch (e) { + return content; + } +}