Skip to content

Commit 960d704

Browse files
authored
chore: formatting release post (#6044)
1 parent 2defb6e commit 960d704

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

scripts/release-post/index.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ import { writeFile } from 'node:fs/promises';
2525
import { resolve } from 'node:path';
2626

2727
import handlebars from 'handlebars';
28+
import { format } from 'prettier';
2829

2930
import { downloadsTable } from './downloadsTable.mjs';
31+
import prettierConfig from '../../.prettierrc.json' assert { type: 'json' };
3032
import { getRelativePath } from '../../next.helpers.mjs';
3133

3234
const 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+
211223
const 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

Comments
 (0)