Skip to content

chore: formatting release post #6044

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Changes from 2 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
15 changes: 15 additions & 0 deletions scripts/release-post/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import { writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';

import handlebars from 'handlebars';
import { format } from 'prettier';

import { downloadsTable } from './downloadsTable.mjs';
import prettierConfig from '../../.prettierrc.json' assert { type: 'json' };
import { getRelativePath } from '../../next.helpers.mjs';

const URLS = {
Expand All @@ -50,6 +52,8 @@ const ERRORS = {
new Error(`Couldn't find matching changelog for ${version}`),
INVALID_STATUS_CODE: (url, status) =>
new Error(`Invalid status (!= 200) while retrieving ${url}: ${status}`),
FAILED_FILE_FORMATTING: reason =>
new Error(`Failed to format Release post: Reason: ${reason}`),
FAILED_FILE_CREATION: reason =>
new Error(`Failed to write Release post: Reason: ${reason}`),
};
Expand Down Expand Up @@ -208,6 +212,16 @@ const renderPost = results => {
return { content: template(templateParameters), ...results };
};

const formatPost = results => {
return new Promise((resolve, reject) => {
format(results.content, { ...prettierConfig, parser: 'markdown' })
.then(formattedContent =>
resolve({ ...results, content: formattedContent })
)
.catch(error => reject(ERRORS.FAILED_FILE_FORMATTING(error.message)));
});
};

const writeToFile = results => {
const blogPostPath = resolve(
__dirname,
Expand Down Expand Up @@ -248,6 +262,7 @@ if (import.meta.url.startsWith('file:')) {
.then(null, findLatestVersion)
.then(fetchDocs)
.then(renderPost)
.then(formatPost)
.then(writeToFile)
.then(
filepath => console.log('Release post created:', filepath),
Expand Down