From 25f2074296ea51891867c7478fdd76ee3cef5736 Mon Sep 17 00:00:00 2001 From: TESTELIN Geoffrey Date: Sat, 22 Jan 2022 22:47:10 +0100 Subject: [PATCH] feat: allow to customize which commits to write Add a list `types` where you can define your generated commits. This will allow for example @semantic-release/release-notes-generator to improve the changelog. --- .releaserc.json | 31 +++------ conventional-changelog.js | 12 ++-- index.js | 54 ++++++++++++---- package-lock.json | 132 +------------------------------------- package.json | 19 +++--- test/test.js | 27 +++++++- writer-opts.js | 116 ++++++++++++++++++++++----------- 7 files changed, 175 insertions(+), 216 deletions(-) diff --git a/.releaserc.json b/.releaserc.json index 6ac4630..880e43c 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -1,7 +1,5 @@ { - "branches": [ - "master" - ], + "branches": ["master"], "plugins": [ [ "@semantic-release/commit-analyzer", @@ -19,14 +17,14 @@ { "type": "perf", "release": "patch" + }, + { + "type": "docs", + "release": "minor" } ], "parserOpts": { - "noteKeywords": [ - "BREAKING CHANGE", - "BREAKING CHANGES", - "BREAKING" - ] + "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] } } ], @@ -35,17 +33,10 @@ { "config": "angular", "parserOpts": { - "noteKeywords": [ - "BREAKING CHANGE", - "BREAKING CHANGES", - "BREAKING" - ] + "noteKeywords": ["BREAKING CHANGE", "BREAKING CHANGES", "BREAKING"] }, "writerOpts": { - "commitsSort": [ - "subject", - "scope" - ], + "commitsSort": ["subject", "scope"], "owner": "C0ZEN" }, "linkCompare": true, @@ -70,11 +61,7 @@ [ "@semantic-release/git", { - "assets": [ - "package.json", - "package-lock.json", - "CHANGELOG.md" - ], + "assets": ["package.json", "package-lock.json", "CHANGELOG.md"], "message": "build(release): new version ${nextRelease.version}" } ], diff --git a/conventional-changelog.js b/conventional-changelog.js index 3495574..074fb86 100644 --- a/conventional-changelog.js +++ b/conventional-changelog.js @@ -4,8 +4,10 @@ const Q = require(`q`); const parserOpts = require(`./parser-opts`); const writerOpts = require(`./writer-opts`); -module.exports = Q.all([parserOpts, writerOpts]).spread( - (parserOpts, writerOpts) => { - return { parserOpts, writerOpts }; - } -); +module.exports = function (config) { + return Q.all([parserOpts, writerOpts(config)]).spread( + (parserOpts, writerOpts) => { + return { parserOpts, writerOpts }; + } + ); +}; diff --git a/index.js b/index.js index 1287fc1..55e23bb 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,54 @@ "use strict"; const Q = require(`q`); +// eslint-disable-next-line @typescript-eslint/naming-convention +const _ = require(`lodash`); const conventionalChangelog = require(`./conventional-changelog`); const parserOpts = require(`./parser-opts`); const recommendedBumpOpts = require(`./conventional-recommended-bump`); const writerOpts = require(`./writer-opts`); -module.exports = Q.all([ - conventionalChangelog, - parserOpts, - recommendedBumpOpts, - writerOpts, -]).spread( - (conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => { - return { +module.exports = function (parameter) { + // parameter passed can be either a config object or a callback function + if (_.isFunction(parameter)) { + // parameter is a callback object + const config = {}; + + Q.all([ conventionalChangelog, parserOpts, recommendedBumpOpts, - writerOpts, - }; + writerOpts(config), + ]).spread( + (conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => { + parameter(null, { + conventionalChangelog, + gitRawCommitsOpts: { noMerges: null }, + parserOpts, + recommendedBumpOpts, + writerOpts, + }); + } + ); + } else { + const config = parameter || {}; + return presetOpts(config); } -); +}; + +function presetOpts(config) { + return Q.all([ + conventionalChangelog, + parserOpts, + recommendedBumpOpts, + writerOpts(config), + ]).spread( + (conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => { + return { + conventionalChangelog, + parserOpts, + recommendedBumpOpts, + writerOpts, + }; + } + ); +} diff --git a/package-lock.json b/package-lock.json index fc374fa..ff454b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "compare-func": "2.0.0", + "lodash": "4.17.21", "q": "1.5.1" }, "devDependencies": { @@ -293,13 +294,6 @@ "node": ">=8" } }, - "node_modules/@commitlint/load/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true, - "optional": true - }, "node_modules/@commitlint/load/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -329,13 +323,6 @@ "node": ">=v8.17.0" } }, - "node_modules/@commitlint/resolve-extends/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true, - "optional": true - }, "node_modules/@commitlint/types": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/@commitlint/types/-/types-9.1.2.tgz", @@ -403,12 +390,6 @@ "node": ">= 4" } }, - "node_modules/@eslint/eslintrc/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "node_modules/@eslint/eslintrc/node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -2644,12 +2625,6 @@ "graceful-fs": "^4.1.6" } }, - "node_modules/commitizen/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "node_modules/commitizen/node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -3492,7 +3467,6 @@ "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz", "integrity": "sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==", "dev": true, - "optional": true, "dependencies": { "@types/parse-json": "^4.0.0", "import-fresh": "^3.1.0", @@ -3509,7 +3483,6 @@ "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.1.0.tgz", "integrity": "sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ==", "dev": true, - "optional": true, "dependencies": { "@babel/code-frame": "^7.0.0", "error-ex": "^1.3.1", @@ -3684,12 +3657,6 @@ "node": ">=8" } }, - "node_modules/cz-customizable/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "node_modules/dargs": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/dargs/-/dargs-7.0.0.tgz", @@ -6750,12 +6717,6 @@ "node": ">= 4" } }, - "node_modules/eslint/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "node_modules/eslint/node_modules/semver": { "version": "7.3.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", @@ -10609,8 +10570,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash-es": { "version": "4.17.15", @@ -17846,12 +17806,6 @@ "node": ">=8" } }, - "node_modules/rxjs-report-usage/node_modules/lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -17915,22 +17869,6 @@ "node": ">=10.18" } }, - "node_modules/semantic-release/node_modules/cosmiconfig": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz", - "integrity": "sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==", - "dev": true, - "dependencies": { - "@types/parse-json": "^4.0.0", - "import-fresh": "^3.1.0", - "parse-json": "^5.0.0", - "path-type": "^4.0.0", - "yaml": "^1.7.2" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/semantic-release/node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -20781,13 +20719,6 @@ "dev": true, "optional": true }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true, - "optional": true - }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -20811,15 +20742,6 @@ "lodash": "^4.17.19", "resolve-from": "^5.0.0", "resolve-global": "^1.0.0" - }, - "dependencies": { - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true, - "optional": true - } } }, "@commitlint/types": { @@ -20876,12 +20798,6 @@ "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", "dev": true }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -22559,12 +22475,6 @@ "graceful-fs": "^4.1.6" } }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -23217,7 +23127,6 @@ "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz", "integrity": "sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==", "dev": true, - "optional": true, "requires": { "@types/parse-json": "^4.0.0", "import-fresh": "^3.1.0", @@ -23231,7 +23140,6 @@ "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.1.0.tgz", "integrity": "sha512-+mi/lmVVNKFNVyLXV31ERiy2CY5E1/F6QtJFEzoChPRwwngMNXRDQ9GJ5WdE2Z2P4AujsOi0/+2qHID68KwfIQ==", "dev": true, - "optional": true, "requires": { "@babel/code-frame": "^7.0.0", "error-ex": "^1.3.1", @@ -23294,14 +23202,6 @@ "lodash": "^4.17.19", "temp": "^0.9.0", "word-wrap": "^1.2.3" - }, - "dependencies": { - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - } } }, "cz-customizable-ghooks": { @@ -23865,12 +23765,6 @@ "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", "dev": true }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true - }, "semver": { "version": "7.3.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", @@ -28583,8 +28477,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash-es": { "version": "4.17.15", @@ -34128,12 +34021,6 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true - }, - "lodash": { - "version": "4.17.20", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", - "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==", - "dev": true } } }, @@ -34194,19 +34081,6 @@ "yargs": "^15.0.1" }, "dependencies": { - "cosmiconfig": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz", - "integrity": "sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg==", - "dev": true, - "requires": { - "@types/parse-json": "^4.0.0", - "import-fresh": "^3.1.0", - "parse-json": "^5.0.0", - "path-type": "^4.0.0", - "yaml": "^1.7.2" - } - }, "figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", diff --git a/package.json b/package.json index 49ae167..29715df 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ }, "dependencies": { "compare-func": "2.0.0", + "lodash": "4.17.21", "q": "1.5.1" }, "devDependencies": { @@ -87,7 +88,11 @@ "@semantic-release/github": "7.0.7", "@typescript-eslint/eslint-plugin": "4.0.1", "@typescript-eslint/parser": "4.0.1", + "better-than-before": "1.0.0", + "c8": "7.1.2", + "chai": "4.2.0", "commitizen": "4.2.1", + "conventional-changelog-core": "4.2.4", "cz-customizable": "6.3.0", "cz-customizable-ghooks": "2.0.0", "eslint": "7.10.0", @@ -98,22 +103,18 @@ "eslint-plugin-prettier": "3.1.3", "eslint-plugin-rxjs": "0.0.2-beta.29", "eslint-plugin-typescript-sort-keys": "2.1.0", + "git-dummy-commit": "1.2.1", "husky": "4.3.8", "lint-staged": "11.2.3", + "mocha": "8.0.1", "prettier": "2.1.1", "semantic-release": "17.1.1", + "shelljs": "0.8.5", + "through2": "4.0.2", "ts-auto-mock": "2.3.5", "ts-node-dev": "1.0.0-pre.63", "tsconfig-paths": "3.11.0", "ttypescript": "1.5.11", - "typescript": "4.0.3", - "chai": "4.2.0", - "mocha": "8.0.1", - "git-dummy-commit": "1.2.1", - "shelljs": "0.8.5", - "through2": "4.0.2", - "better-than-before": "1.0.0", - "conventional-changelog-core": "4.2.4", - "c8": "7.1.2" + "typescript": "4.0.3" } } diff --git a/test/test.js b/test/test.js index b8745ed..c70fad3 100644 --- a/test/test.js +++ b/test/test.js @@ -101,9 +101,12 @@ betterThanBefore.setups([ `This reverts commit 5678.`, ]); }, + function () { + gitDummyCommit(`docs(website): add a new page in the website`); + }, ]); -describe(`angular preset`, function () { +describe(`Sonia preset`, function () { it(`should work if there is no semver tag`, function (done) { preparing(1); @@ -131,7 +134,7 @@ describe(`angular preset`, function () { expect(chunk).to.include(`**compile:** The Change is huge.`); expect(chunk).to.include(`Build System`); expect(chunk).to.include(`Continuous Integration`); - expect(chunk).to.include(`Features`); + expect(chunk).to.include(`:rocket: Features`); expect(chunk).to.include(`Bug Fixes`); expect(chunk).to.include(`Performance Improvements`); expect(chunk).to.include(`Reverts`); @@ -452,4 +455,24 @@ describe(`angular preset`, function () { }) ); }); + + it(`should display the docs commits when the preset config is configured to allow docs commit to be generated`, function (done) { + preparing(10); + + conventionalChangelogCore({ + config: require(`../`)({ + types: [`docs`], + }), + }) + .on(`error`, function (err) { + done(err); + }) + .pipe( + through(function (chunk) { + chunk = chunk.toString(); + expect(chunk).to.include(`:books: Documentation`); + done(); + }) + ); + }); }); diff --git a/writer-opts.js b/writer-opts.js index 8479b77..874097b 100644 --- a/writer-opts.js +++ b/writer-opts.js @@ -5,23 +5,29 @@ const Q = require(`q`); const readFile = Q.denodeify(require(`fs`).readFile); const resolve = require(`path`).resolve; -module.exports = Q.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`), -]).spread((template, header, commit, footer) => { - const writerOpts = getWriterOpts(); - - writerOpts.mainTemplate = template; - writerOpts.headerPartial = header; - writerOpts.commitPartial = commit; - writerOpts.footerPartial = footer; - - return writerOpts; -}); - -function getWriterOpts() { +module.exports = function (config) { + config = defaultConfig(config); + + return Q.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`), + ]).spread((template, header, commit, footer) => { + const writerOpts = getWriterOpts(config); + + writerOpts.mainTemplate = template; + writerOpts.headerPartial = header; + writerOpts.commitPartial = commit; + writerOpts.footerPartial = footer; + + return writerOpts; + }); +}; + +function getWriterOpts(config) { + config = defaultConfig(config); + return { commitGroupsSort: `title`, commitsSort: [`scope`, `subject`], @@ -37,28 +43,59 @@ function getWriterOpts() { shouldDiscard = false; }); - if (commit.type === `feat`) { + if ( + commit.type === `feat` && + (!shouldDiscard || config.types.includes(`feat`)) + ) { commit.type = `:rocket: Features`; - } else if (commit.type === `fix`) { + } else if ( + commit.type === `fix` && + (!shouldDiscard || config.types.includes(`fix`)) + ) { commit.type = `:bug: Bug Fixes`; - } else if (commit.type === `perf`) { + } else if ( + commit.type === `perf` && + (!shouldDiscard || config.types.includes(`perf`)) + ) { commit.type = `:zap: Performance Improvements`; - } else if (commit.type === `revert` || commit.revert) { + } else if ( + (commit.type === `revert` && + (!shouldDiscard || config.types.includes(`revert`))) || + commit.revert + ) { commit.type = `:rewind: Reverts`; + } else if ( + commit.type === `docs` && + (!shouldDiscard || config.types.includes(`docs`)) + ) { + commit.type = `:books: Documentation`; + } else if ( + commit.type === `style` && + (!shouldDiscard || config.types.includes(`style`)) + ) { + commit.type = `:star2: Styles`; + } else if ( + commit.type === `refactor` && + (!shouldDiscard || config.types.includes(`refactor`)) + ) { + commit.type = `:sparkles: Code Refactoring`; + } else if ( + commit.type === `test` && + (!shouldDiscard || config.types.includes(`test`)) + ) { + commit.type = `:microscope: Tests`; + } else if ( + commit.type === `build` && + (!shouldDiscard || config.types.includes(`build`)) + ) { + commit.type = `:wrench: Build System`; + } else if ( + commit.type === `ci` && + (!shouldDiscard || config.types.includes(`ci`)) + ) { + commit.type = `:robot: Continuous Integration`; } else if (shouldDiscard) { return; - } else if (commit.type === `docs`) { - commit.type = `:books: Documentation`; - } else if (commit.type === `style`) { - commit.type = `Styles`; - } else if (commit.type === `refactor`) { - commit.type = `Code Refactoring`; - } else if (commit.type === `test`) { - commit.type = `Tests`; - } else if (commit.type === `build`) { - commit.type = `Build System`; - } else if (commit.type === `ci`) { - commit.type = `Continuous Integration`; } if (commit.scope === `*`) { @@ -98,14 +135,17 @@ function getWriterOpts() { // remove references that already appear in the subject commit.references = commit.references.filter((reference) => { - if (issues.indexOf(reference.issue) === -1) { - return true; - } - - return false; + return issues.indexOf(reference.issue) === -1; }); return commit; }, }; } + +function defaultConfig(config) { + config = config || {}; + config.types = config.types || [`feat`, `fix`, `perf`, `revert`]; + + return config; +}