@@ -25,8 +25,10 @@ import { writeFile } from 'node:fs/promises';
25
25
import { resolve } from 'node:path' ;
26
26
27
27
import handlebars from 'handlebars' ;
28
+ import { format } from 'prettier' ;
28
29
29
30
import { downloadsTable } from './downloadsTable.mjs' ;
31
+ import prettierConfig from '../../.prettierrc.json' assert { type : 'json ' } ;
30
32
import { getRelativePath } from '../../next.helpers.mjs' ;
31
33
32
34
const URLS = {
@@ -50,6 +52,8 @@ const ERRORS = {
50
52
new Error ( `Couldn't find matching changelog for ${ version } ` ) ,
51
53
INVALID_STATUS_CODE : ( url , status ) =>
52
54
new Error ( `Invalid status (!= 200) while retrieving ${ url } : ${ status } ` ) ,
55
+ FAILED_FILE_FORMATTING : reason =>
56
+ new Error ( `Failed to format Release post: Reason: ${ reason } ` ) ,
53
57
FAILED_FILE_CREATION : reason =>
54
58
new Error ( `Failed to write Release post: Reason: ${ reason } ` ) ,
55
59
} ;
@@ -208,6 +212,14 @@ const renderPost = results => {
208
212
return { content : template ( templateParameters ) , ...results } ;
209
213
} ;
210
214
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
+
211
223
const writeToFile = results => {
212
224
const blogPostPath = resolve (
213
225
__dirname ,
@@ -248,6 +260,7 @@ if (import.meta.url.startsWith('file:')) {
248
260
. then ( null , findLatestVersion )
249
261
. then ( fetchDocs )
250
262
. then ( renderPost )
263
+ . then ( formatPost )
251
264
. then ( writeToFile )
252
265
. then (
253
266
filepath => console . log ( 'Release post created:' , filepath ) ,
0 commit comments