1616import markdown_it
1717from cfbs .pretty import pretty_file
1818
19- from cfengine_cli .markdowner import markdown_prettify
2019from cfengine_cli .utils import UserError
2120
2221
@@ -287,19 +286,49 @@ def _markdown_code_checker(
287286 )
288287 if cleanup :
289288 os .remove (snippet_path )
290- if autoformat :
291- markdown_prettify (origin_path )
292289
290+ def _run_black ():
291+ path = "."
292+ assert os .path .isdir (path )
293+ try :
294+ subprocess .run (
295+ ["black" , path ],
296+ capture_output = True ,
297+ text = True ,
298+ check = True ,
299+ cwd = path ,
300+ )
301+ except :
302+ raise UserError ("Encountered an error running prettier" )
303+
304+
305+ def _run_prettier ():
306+ path = "."
307+ assert os .path .isdir (path )
308+ try :
309+ subprocess .run (
310+ ["prettier" , "--write" , "**.markdown" , "**.md" ],
311+ capture_output = True ,
312+ text = True ,
313+ check = True ,
314+ cwd = path ,
315+ )
316+ except :
317+ raise UserError ("Encountered an error running prettier" )
293318
294319def update_docs () -> int :
295320 """
296- Iterate through entire docs repo (.), autoformatting all JSONs.
297-
298- Will be expanded to more types of formatting in the future.
321+ Iterate through entire docs repo (.), autoformatting as much as possible:
322+ - python code with black
323+ - markdown files with prettier
324+ - code blocks inside markdown files are formatted for the formats supported by prettier
325+ - JSON code blocks are re-formatted by cfbs pretty (we plan to expand this to CFEngine code blocks)
299326
300327 Run by the command:
301328 cfengine dev docs-format
302329 """
330+ _run_black ()
331+ _run_prettier ()
303332 _markdown_code_checker (
304333 path = "." ,
305334 syntax_check = False ,
@@ -314,7 +343,9 @@ def update_docs() -> int:
314343
315344
316345def check_docs () -> int :
317- """Entry point to be called by other files
346+ """
347+ Run checks / tests on docs.
348+ Currently only JSON syntax checking.
318349
319350 Run by the command:
320351 cfengine dev docs-checking"""
0 commit comments