The Node.js® Website

chore: formatting release post (#6044)

authored by Levi (Nguyễn Lương Huy) and committed by GitHub 960d704f 2defb6e6

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