diff --git a/.prettierignore b/.prettierignore index 2b981d264..ca904e31e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,3 @@ -CHANGELOG.md .cache-jest dist node_modules diff --git a/documentation/scripts/generate-changelog.mjs b/documentation/scripts/generate-changelog.mjs index 8c320309b..db990ee54 100644 --- a/documentation/scripts/generate-changelog.mjs +++ b/documentation/scripts/generate-changelog.mjs @@ -3,10 +3,12 @@ import { getDirectoryName } from './get-directory-name.mjs'; import * as LOGGER from './logger.mjs'; import FS from 'fs-extra'; import _ from 'lodash'; +import XREG_EXP from 'xregexp'; import { execSync } from 'child_process'; const CONTEXT = `generate-changelog`; -const CHANGELOG_PATH = `documentation/docs/15-changelog.md`; +const CHANGELOG_PATH = `CHANGELOG.md`; +const DOCUMENTATION_CHANGELOG_PATH = `documentation/docs/15-changelog.md`; /** * @description @@ -18,13 +20,19 @@ async function initialize() { navigateToRoot(); + LOGGER.debug(CONTEXT, CHALK.text(`Linting the original changelog...`)); + execSync(`npm run lint:other:this -- ${CHANGELOG_PATH}`, { + stdio: `inherit`, + }); + LOGGER.success(CONTEXT, CHALK.text(`Original changelog linted`)); + const originalChangelog = await loadOriginalChangelog(); const documentationChangelog = await loadDocumentationChangelog(); await mergeOriginalIntoDocumentationChangelog(originalChangelog, documentationChangelog); LOGGER.debug(CONTEXT, CHALK.text(`Linting the documentation changelog...`)); - execSync(`npm run lint:other:this -- ${CHANGELOG_PATH}`, { + execSync(`npm run lint:other:this -- ${DOCUMENTATION_CHANGELOG_PATH}`, { stdio: `inherit`, }); LOGGER.success(CONTEXT, CHALK.text(`Documentation changelog linted`)); @@ -48,7 +56,7 @@ async function initialize() { async function loadOriginalChangelog() { LOGGER.debug(CONTEXT, CHALK.text(`Loading the original changelog...`)); - const changelog = await FS.readFile(`CHANGELOG.md`, `utf-8`); + const changelog = await FS.readFile(CHANGELOG_PATH, `utf-8`); LOGGER.success(CONTEXT, CHALK.text(`Original changelog loaded`)); @@ -63,7 +71,7 @@ async function loadOriginalChangelog() { async function loadDocumentationChangelog() { LOGGER.debug(CONTEXT, CHALK.text(`Loading the documentation changelog...`)); - const changelog = await FS.readFile(CHANGELOG_PATH, `utf-8`); + const changelog = await FS.readFile(DOCUMENTATION_CHANGELOG_PATH, `utf-8`); LOGGER.success(CONTEXT, CHALK.text(`Documentation changelog loaded`)); @@ -79,7 +87,7 @@ async function loadDocumentationChangelog() { async function updateDocumentationChangelog(content) { LOGGER.debug(CONTEXT, CHALK.text(`Updating the documentation changelog...`)); - await FS.writeFile(CHANGELOG_PATH, content); + await FS.writeFile(DOCUMENTATION_CHANGELOG_PATH, content); LOGGER.success(CONTEXT, CHALK.text(`Documentation changelog updated`)); } @@ -114,9 +122,10 @@ function replaceDocumentationChangelogContent(originalChangelog, documentationCh LOGGER.debug(CONTEXT, CHALK.text(`Replacing the content of the documentation changelog...`)); const frontMatter = getFrontMatter(documentationChangelog); - let newContent = `${frontMatter}${originalChangelog}`; + let newContent = replaceTitle(originalChangelog); - newContent = replaceTitle(newContent); + newContent = formatBreakOfLines(newContent); + newContent = `${frontMatter}${newContent}`; LOGGER.success(CONTEXT, CHALK.text(`Documentation changelog content replaced`)); @@ -154,6 +163,26 @@ function replaceTitle(content) { return newContent; } +/** + * @param {Readonly} content The updated documentation changelog + * @returns {string} The documentation changelog with the formatted break of lines + */ +function formatBreakOfLines(content) { + LOGGER.debug(CONTEXT, CHALK.text(`Formatting the break of lines...`)); + + // eslint-disable-next-line new-cap + const regexpCommitType = XREG_EXP(`(?^- \\*\\*.*)(?\\n)(? \\w+)`, `gim`); + let newContent = XREG_EXP.replace(content, regexpCommitType, `$ $$`, `all`); + // eslint-disable-next-line new-cap + const regexpBodySentence = XREG_EXP(`(? .+)(?\\n)`, `gim`); + + newContent = XREG_EXP.replace(newContent, regexpBodySentence, `$ $`, `all`); + + LOGGER.success(CONTEXT, CHALK.text(`Break of lines formatted`)); + + return newContent; +} + /** * */ diff --git a/package-lock.json b/package-lock.json index 794e70481..87f062b45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,7 +70,8 @@ "tsconfig-paths": "4.1.0", "ttypescript": "1.5.13", "typescript": "4.7.4", - "weak-napi": "2.0.2" + "weak-napi": "2.0.2", + "xregexp": "5.1.1" }, "engines": { "node": "16.16.0", @@ -629,6 +630,19 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/runtime-corejs3": { + "version": "7.18.9", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.18.9.tgz", + "integrity": "sha512-qZEWeccZCrHA2Au4/X05QW5CMdm4VjUDCrGq5gf1ZDcM4hRqreKrtwAn7yci9zfgAS9apvnsFXiGBHBAxZdK9A==", + "dev": true, + "dependencies": { + "core-js-pure": "^3.20.2", + "regenerator-runtime": "^0.13.4" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/template": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.16.7.tgz", @@ -4288,6 +4302,17 @@ "safe-buffer": "~5.1.1" } }, + "node_modules/core-js-pure": { + "version": "3.24.1", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.24.1.tgz", + "integrity": "sha512-r1nJk41QLLPyozHUUPmILCEMtMw24NG4oWK6RbsDdjzQgg9ZvrUsPBj1MnG0wXXp1DCDU6j+wUvEmBSrtRbLXg==", + "dev": true, + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -18003,6 +18028,15 @@ "node": "^12.13.0 || ^14.15.0 || >=16" } }, + "node_modules/xregexp": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-5.1.1.tgz", + "integrity": "sha512-fKXeVorD+CzWvFs7VBuKTYIW63YD1e1osxwQ8caZ6o1jg6pDAbABDG54LCIq0j5cy7PjRvGIq6sef9DYPXpncg==", + "dev": true, + "dependencies": { + "@babel/runtime-corejs3": "^7.16.5" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", @@ -18588,6 +18622,16 @@ "regenerator-runtime": "^0.13.4" } }, + "@babel/runtime-corejs3": { + "version": "7.18.9", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.18.9.tgz", + "integrity": "sha512-qZEWeccZCrHA2Au4/X05QW5CMdm4VjUDCrGq5gf1ZDcM4hRqreKrtwAn7yci9zfgAS9apvnsFXiGBHBAxZdK9A==", + "dev": true, + "requires": { + "core-js-pure": "^3.20.2", + "regenerator-runtime": "^0.13.4" + } + }, "@babel/template": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.16.7.tgz", @@ -21378,6 +21422,12 @@ "safe-buffer": "~5.1.1" } }, + "core-js-pure": { + "version": "3.24.1", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.24.1.tgz", + "integrity": "sha512-r1nJk41QLLPyozHUUPmILCEMtMw24NG4oWK6RbsDdjzQgg9ZvrUsPBj1MnG0wXXp1DCDU6j+wUvEmBSrtRbLXg==", + "dev": true + }, "core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", @@ -31477,6 +31527,15 @@ "signal-exit": "^3.0.7" } }, + "xregexp": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-5.1.1.tgz", + "integrity": "sha512-fKXeVorD+CzWvFs7VBuKTYIW63YD1e1osxwQ8caZ6o1jg6pDAbABDG54LCIq0j5cy7PjRvGIq6sef9DYPXpncg==", + "dev": true, + "requires": { + "@babel/runtime-corejs3": "^7.16.5" + } + }, "xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 1da088f8b..a4bbc1cd9 100644 --- a/package.json +++ b/package.json @@ -161,6 +161,7 @@ "tsconfig-paths": "4.1.0", "ttypescript": "1.5.13", "typescript": "4.7.4", - "weak-napi": "2.0.2" + "weak-napi": "2.0.2", + "xregexp": "5.1.1" } }