Skip to content

Commit

Permalink
chore(changelog): updating changelog script to separate by folder (#4441
Browse files Browse the repository at this point in the history
)

### Related Ticket(s)

No related issue

### Description

This is a modification of the changelog generation script to split up
the commit changes based on changes in each package folder. This will
help with separating out the logs based on the changes that went on in
the corresponding package folders in an automated way. From what I could
 tell, there is no existing open source package that can generate the
 logs in the desired way.

The pinned issue has been updated using the script:
#3598

NOTE: one thing I did notice in one library during my research that I liked is where it was putting all of the line items with the same heading and grouping the changes into sub-bullets. Might look at that for an enhancement to the script, as well as alphabetically ordering the headings.

### Changelog

**Changed**

- Changelog script updates
  • Loading branch information
jeffchew authored Nov 11, 2020
1 parent c01540f commit b3e99c0
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions tasks/get-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const args = program.parse(process.argv);
*
* @type {string}
*/
const tagFrom = args.tagFrom;
const { tagFrom } = args;

/**
* Tag To (-t)
*
* @type {string}
*/
const tagTo = args.tagTo;
const { tagTo } = args;

/**
* Uses a delimiter for splitting the comments into an array
Expand All @@ -47,14 +47,17 @@ const delimiter = '----DELIMITER----';
/**
* Returns back the commits in an array
*
* @param {string} folder Folder to get commit log for
* @returns {string[]} Commits array of objects
*/
function getCommits() {
function getCommits(folder) {
const toTag = tagTo !== undefined ? tagTo : 'HEAD';

// Gets the git output between the two tags
const output = child
.execSync(`git log ${tagFrom}..${toTag} --pretty=format:"%s"${delimiter}`)
.execSync(
`git log ${tagFrom}..${toTag} --pretty=format:"%s"${delimiter} -- ${folder}`
)
.toString('utf-8');

// Generates the array of commit comments
Expand All @@ -64,42 +67,48 @@ function getCommits() {
/**
* Gets the changelog content
*
* @returns {*} Changelog content
* @param {string} pkgName Package name
* @param {string} folder Folder for git log
* @returns {string} Changelog content
*/
function getChangelog() {
function getChangelog(pkgName, folder) {
// Stores the changelog
let changelog = '';
let changelog = `## ${pkgName}\n`;

// Stores the list of features
const features = [];

// Stores the list of fixes
const fixes = [];

const commitsArray = getCommits();
const commitsArray = getCommits(folder);

commitsArray.forEach(commit => {
commit = commit.replace(delimiter, '');
const commitParse = commit.replace(delimiter, '');
if (commit.startsWith('feat(')) {
let pushFeat = commit.replace('feat(', '- **').replace('):', '**: ');
const pushFeat = commitParse
.replace('feat(', '- **')
.replace('):', '**: ');
features.push(`${pushFeat}\n`);
}
if (commit.startsWith('fix(')) {
let pushFeat = commit.replace('fix(', '- **').replace('):', '**: ');
const pushFeat = commitParse
.replace('fix(', '- **')
.replace('):', '**: ');
fixes.push(`${pushFeat}\n`);
}
});

if (features.length) {
changelog += `## Features\n`;
changelog += `### Features\n`;
features.forEach(feature => {
changelog += feature;
});
changelog += '\n';
}

if (fixes.length) {
changelog += `## Fixes\n`;
changelog += `### Fixes\n`;
fixes.forEach(fix => {
changelog += fix;
});
Expand All @@ -109,4 +118,19 @@ function getChangelog() {
return changelog;
}

console.log(getChangelog());
/**
* Renders the log
*/
function generateLog() {
let log = '';

log += getChangelog('Web Components', './packages/web-components');
log += getChangelog('React', './packages/react');
log += getChangelog('Styles', './packages/styles');
log += getChangelog('Services', './packages/services');
log += getChangelog('Utilities', './packages/utilities');

console.log(log);
}

generateLog();

0 comments on commit b3e99c0

Please sign in to comment.