@@ -25,8 +25,10 @@ import { writeFile } from 'node:fs/promises';
2525import { resolve } from 'node:path' ;
2626
2727import handlebars from 'handlebars' ;
28+ import { format } from 'prettier' ;
2829
2930import { downloadsTable } from './downloadsTable.mjs' ;
31+ import prettierConfig from '../../.prettierrc.json' assert { type : 'json ' } ;
3032import { getRelativePath } from '../../next.helpers.mjs' ;
3133
3234const URLS = {
@@ -50,6 +52,8 @@ const ERRORS = {
5052 new Error ( `Couldn't find matching changelog for ${ version } ` ) ,
5153 INVALID_STATUS_CODE : ( url , status ) =>
5254 new Error ( `Invalid status (!= 200) while retrieving ${ url } : ${ status } ` ) ,
55+ FAILED_FILE_FORMATTING : reason =>
56+ new Error ( `Failed to format Release post: Reason: ${ reason } ` ) ,
5357 FAILED_FILE_CREATION : reason =>
5458 new Error ( `Failed to write Release post: Reason: ${ reason } ` ) ,
5559} ;
@@ -208,6 +212,14 @@ const renderPost = results => {
208212 return { content : template ( templateParameters ) , ...results } ;
209213} ;
210214
215+ const formatPost = results => {
216+ return new Promise ( ( resolve , reject ) => {
217+ format ( results . content , { ...prettierConfig , parser : 'markdown' } )
218+ . then ( content => resolve ( { ...results , content } ) )
219+ . catch ( error => reject ( ERRORS . FAILED_FILE_FORMATTING ( error . message ) ) ) ;
220+ } ) ;
221+ } ;
222+
211223const writeToFile = results => {
212224 const blogPostPath = resolve (
213225 __dirname ,
@@ -248,6 +260,7 @@ if (import.meta.url.startsWith('file:')) {
248260 . then ( null , findLatestVersion )
249261 . then ( fetchDocs )
250262 . then ( renderPost )
263+ . then ( formatPost )
251264 . then ( writeToFile )
252265 . then (
253266 filepath => console . log ( 'Release post created:' , filepath ) ,
0 commit comments