Skip to content

Commit

Permalink
BREAKING CHANGES(conventional-changelog): All preset exports factory …
Browse files Browse the repository at this point in the history
  • Loading branch information
literat committed Jul 26, 2024
1 parent cd3b0e1 commit e103c4a
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable no-param-reassign */
/* eslint-disable jsdoc/require-jsdoc */
const { readFile } = require('fs').promises;
const { resolve } = require('path');

async function createConventionalChangelogOpts (parserOpts, writerOpts) {
return Promise.all([
readFile(resolve(__dirname, 'templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/commit.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8'),
]).then(([template, header, commit, footer]) => {
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;
writerOpts.footerPartial = footer;

return {
parserOpts,
writerOpts,
};
});
}

module.exports.createConventionalChangelogOpts = createConventionalChangelogOpts;
27 changes: 16 additions & 11 deletions packages/conventional-changelog-lmc-bitbucket/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const conventionalChangelog = require(`./conventional-changelog`);
const { parserOpts, writerOpts, recommendedBumpOpts } = require('@lmc-eu/conventional-changelog-lmc');
/* eslint-disable jsdoc/require-jsdoc */
const { createConventionalChangelogOpts } = require(`./conventionalChangelog`);
const { createParserOpts, createWriterOpts, createConventionalRecommendedBumpOpts } = require('@lmc-eu/conventional-changelog-lmc');

module.exports = Promise.all([conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts]).then(
// Using same configuration as other configurations
// Did not find any documentation whether the output must be in this format
// eslint-disable-next-line no-shadow
([conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts]) => ({
conventionalChangelog,
async function createPreset () {
const parserOpts = createParserOpts()
const writerOpts = createWriterOpts()
const recommendedBumpOpts = createConventionalRecommendedBumpOpts(parserOpts)
const conventionalChangelog = await createConventionalChangelogOpts(parserOpts, writerOpts)

return {
parserOpts,
recommendedBumpOpts,
writerOpts,
}),
);
recommendedBumpOpts,
conventionalChangelog
}
}

module.exports = createPreset;

This file was deleted.

34 changes: 0 additions & 34 deletions packages/conventional-changelog-lmc/src/bump-opts.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable jsdoc/require-jsdoc */

function createConventionalRecommendedBumpOpts (parserOpts) {
return {
parserOpts,

whatBump: (commits) => {
let level = 2;
let breakings = 0;
let features = 0;

commits.forEach((commit) => {
if (commit.notes.length > 0) {
breakings += commit.notes.length;
level = 0;
} else if (commit.type === 'BREAKING CHANGE' || commit.type === 'BREAKING CHANGES') {
breakings += 1;
level = 0;
} else if (commit.type === `Feat`) {
features += 1;
if (level === 2) {
level = 1;
}
}
});

return {
level,
reason:
breakings === 1
? `There are ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`,
};
},
};
};

module.exports.createConventionalRecommendedBumpOpts = createConventionalRecommendedBumpOpts;
12 changes: 6 additions & 6 deletions packages/conventional-changelog-lmc/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const parserOpts = require('./parser-opts');
const writerOpts = require('./writer-opts');
const recommendedBumpOpts = require('./bump-opts');
const { createParserOpts } = require('./parserOpts');
const { createWriterOpts } = require('./writerOpts');
const { createConventionalRecommendedBumpOpts } = require('./conventionalRecommendedBump');

module.exports = {
parserOpts,
recommendedBumpOpts,
writerOpts,
createParserOpts,
createWriterOpts,
createConventionalRecommendedBumpOpts,
};
8 changes: 0 additions & 8 deletions packages/conventional-changelog-lmc/src/parser-opts.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/conventional-changelog-lmc/src/parserOpts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable jsdoc/require-jsdoc */

function createParserOpts () {
return {
headerPattern: /^(?:Pull request #[0-9]+: )?(?:([a-zA-Z]*-[0-9_]*)(?: ))* ?([\w ]*)(?:\((.*)\))?!?: (.*)$/,
breakingHeaderPattern: /^(?:([a-zA-Z]*-[0-9_]*)(?: ))* ?([\w ]*)(?:\((.*)\))?!: (.*)$/,
headerCorrespondence: ['body', 'type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES'],
revertPattern: /^(?:Revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
revertCorrespondence: ['header', 'hash'],
};
};

module.exports.createParserOpts = createParserOpts;
102 changes: 0 additions & 102 deletions packages/conventional-changelog-lmc/src/writer-opts.js

This file was deleted.

Loading

0 comments on commit e103c4a

Please sign in to comment.