Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: format with prettier #31

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
Loading