From bec88242140023d8613ba80c554d12b3eccb4fd9 Mon Sep 17 00:00:00 2001 From: Robert Kieffer Date: Tue, 24 Dec 2024 12:52:37 -0800 Subject: [PATCH] fix: format with prettier --- cli.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index f58a30f..bdf2ad0 100755 --- a/cli.js +++ b/cli.js @@ -34,7 +34,7 @@ if (outputName) { /** * Render input file to output. (args passed by fs.watchFile) */ -function run(curr, prev) { +async function run(curr, prev) { // Do nothing if file not modified if (curr && prev && curr.mtime === prev.mtime) return; @@ -50,6 +50,19 @@ function run(curr, prev) { lame: argv.lame }); + // Format using prettier (if available) + try { + const prettier = require('prettier'); + const config = await prettier.resolveConfig(outputPath); + console.log('CONFIG', config); + markdown = await prettier.format(markdown, { + parser: 'markdown', + ...config + }); + } catch (err) { + // Ignore + } + // Write to output (file or stdout) if (outputPath) { fs.writeFileSync(outputPath, markdown); @@ -64,7 +77,7 @@ function run(curr, prev) { } } -run(); +run().catch(console.error); // If --watch, rerender when file changes if (argv.watch) fs.watchFile(inputPath, run);