Skip to content

Commit

Permalink
chore(docs): improve the changelog generator for the website
Browse files Browse the repository at this point in the history
The new version is adding some break of lines.
This will help to have a better readability.
Closes #836.
  • Loading branch information
C0ZEN committed Aug 24, 2022
1 parent 1fd8f22 commit fd898d0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 10 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CHANGELOG.md
.cache-jest
dist
node_modules
Expand Down
43 changes: 36 additions & 7 deletions documentation/scripts/generate-changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`));
Expand All @@ -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`));

Expand All @@ -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`));

Expand All @@ -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`));
}
Expand Down Expand Up @@ -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`));

Expand Down Expand Up @@ -154,6 +163,26 @@ function replaceTitle(content) {
return newContent;
}

/**
* @param {Readonly<string>} 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(`(?<commit>^- \\*\\*.*)(?<eol>\\n)(?<description> \\w+)`, `gim`);
let newContent = XREG_EXP.replace(content, regexpCommitType, `$<commit> $<eol>$<description>`, `all`);
// eslint-disable-next-line new-cap
const regexpBodySentence = XREG_EXP(`(?<sentence> .+)(?<eol>\\n)`, `gim`);

newContent = XREG_EXP.replace(newContent, regexpBodySentence, `$<sentence> $<eol>`, `all`);

LOGGER.success(CONTEXT, CHALK.text(`Break of lines formatted`));

return newContent;
}

/**
*
*/
Expand Down
61 changes: 60 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit fd898d0

Please sign in to comment.