From 3b7ff9a6109de590a07392a70ac63880aad73a10 Mon Sep 17 00:00:00 2001 From: Ed Date: Sun, 3 Nov 2019 17:32:29 +0100 Subject: [PATCH] refactor: use object literal to transform commit type --- .gitignore | 3 ++ package-lock.json | 6 +-- plugins.json | 102 ++++++++++++++++++++++------------------------ release.config.js | 66 +++++++++++++----------------- 4 files changed, 83 insertions(+), 94 deletions(-) diff --git a/.gitignore b/.gitignore index 0b225dd..42b2b1e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ node_modules # NPM files .npmrc + +# local configuration +.releaerc.yaml diff --git a/package-lock.json b/package-lock.json index b1de469..9d062ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -663,9 +663,9 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "conventional-changelog-angular": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.3.tgz", - "integrity": "sha512-YD1xzH7r9yXQte/HF9JBuEDfvjxxwDGGwZU1+ndanbY0oFgA+Po1T9JDSpPLdP0pZT6MhCAsdvFKC4TJ4MTJTA==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-5.0.5.tgz", + "integrity": "sha512-RrkdWnL/TVyWV1ayWmSsrWorsTDqjL/VwG5ZSEneBQrd65ONcfeA1cW7FLtNweQyMiKOyriCMTKRSlk18DjTrw==", "requires": { "compare-func": "^1.3.1", "q": "^1.5.1" diff --git a/plugins.json b/plugins.json index 25d11d8..c032731 100644 --- a/plugins.json +++ b/plugins.json @@ -1,54 +1,48 @@ -{ - "plugins": [ - [ - "@semantic-release/commit-analyzer", - { - "releaseRules": [ - { - "type": "build", - "release": "patch" - }, - { - "type": "ci", - "release": "patch" - }, - { - "type": "chore", - "release": "patch" - }, - { - "type": "docs", - "release": "patch" - }, - { - "type": "refactor", - "release": "patch" - }, - { - "type": "style", - "release": "patch" - }, - { - "type": "test", - "release": "patch" - } - ] - } - ], - "@semantic-release/release-notes-generator", - "@semantic-release/changelog", - "@semantic-release/npm", - [ - "@semantic-release/git", - { - "assets": [ - "package.json", - "package-lock.json", - "CHANGELOG.md" - ], - "message": "release(version): Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" - } - ], - "@semantic-release/github" - ] -} +[ + [ + "@semantic-release/commit-analyzer", + { + "releaseRules": [ + { + "type": "build", + "release": "patch" + }, + { + "type": "ci", + "release": "patch" + }, + { + "type": "chore", + "release": "patch" + }, + { + "type": "docs", + "release": "patch" + }, + { + "type": "refactor", + "release": "patch" + }, + { + "type": "style", + "release": "patch" + }, + { + "type": "test", + "release": "patch" + } + ] + } + ], + "@semantic-release/release-notes-generator", + "@semantic-release/changelog", + "@semantic-release/npm", + [ + "@semantic-release/git", + { + "assets": ["package.json", "package-lock.json", "CHANGELOG.md"], + "message": "release(version): Release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ], + "@semantic-release/github" +] diff --git a/release.config.js b/release.config.js index 597f023..096b069 100644 --- a/release.config.js +++ b/release.config.js @@ -1,47 +1,36 @@ -const plugins = require("./plugins.json"); +const plugins = require("./plugins"); -parserOpts = { - mergePattern: /^Merge pull request #(\d+) from (.*)$/, - mergeCorrespondence: ["id", "source"] +const transformCommitType = type => { + const commitTypeMapping = { + feat: "Features", + fix: "Bug Fixes", + perf: "Performance Improvements", + revert: "Reverts", + docs: "Documentation", + style: "Styles", + refactor: "Code Refactoring", + test: "Tests", + build: "Build System", + ci: "Continuous Integration", + chore: "Chores", + default: () => { + return; + } + }; + return commitTypeMapping[type] || commitTypeMapping["default"]; }; -releaseRules = [{ type: "refactor", release: "patch" }]; - -customTransform = (commit, context) => { +const customTransform = (commit, context) => { const issues = []; commit.notes.forEach(note => { note.title = `BREAKING CHANGES`; }); - if (commit.type === `feat`) { - commit.type = `Features`; - } else if (commit.type === `fix`) { - commit.type = `Bug Fixes`; - } else if (commit.type === `perf`) { - commit.type = `Performance Improvements`; - } else if (commit.type === `revert`) { - commit.type = `Reverts`; - } else if (commit.type === `docs`) { - commit.type = `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`; - } else if (commit.type === `chore`) { - commit.type = `Chores`; - } else { - return; - } + commit.type = transformCommitType(commit.type); - if (commit.scope === `*`) { - commit.scope = ``; + if (commit.scope === "*") { + commit.scope = ""; } if (typeof commit.hash === `string`) { @@ -88,8 +77,11 @@ customTransform = (commit, context) => { }; module.exports = { - releaseRules, - parserOpts, + releaseRules: plugins[0][1].releaseRules, + parserOpts: { + mergePattern: /^Merge pull request #(\d+) from (.*)$/, + mergeCorrespondence: ["id", "source"] + }, writerOpts: { transform: customTransform }, - ...plugins + plugins };