diff --git a/README.md b/README.md index 6f1a9169..50e80e5f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Options: --append-git-tag [string] # string to append to git tag command --prepend # prepend changelog to output file --stdout # output changelog to stdout + --plugins [...name] # use plugins to augment commit/merge/release information -V, --version # output the version number -h, --help # output usage information diff --git a/package.json b/package.json index dbec1e20..904602ee 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "dependencies": { "commander": "^7.2.0", "handlebars": "^4.7.7", + "import-cwd": "^3.0.0", "node-fetch": "^2.6.1", "parse-github-url": "^1.0.2", "semver": "^7.3.5" diff --git a/src/releases.js b/src/releases.js index 2904fc2b..96e0509a 100644 --- a/src/releases.js +++ b/src/releases.js @@ -9,6 +9,13 @@ const parseReleases = async (tags, options, onParsed) => { const commits = await fetchCommits(tag.diff, options) const merges = commits.filter(commit => commit.merge).map(commit => commit.merge) const fixes = commits.filter(commit => commit.fixes).map(commit => ({ fixes: commit.fixes, commit })) + + for (const plugin of options.plugins) { + if (plugin.processCommits) await plugin.processCommits(commits) + if (plugin.processMerges) await plugin.processMerges(merges) + if (plugin.processFixes) await plugin.processFixes(merges) + } + const emptyRelease = merges.length === 0 && fixes.length === 0 const { message } = commits[0] || { message: null } const breakingCount = commits.filter(c => c.breaking).length @@ -27,6 +34,11 @@ const parseReleases = async (tags, options, onParsed) => { fixes } })) + + for (const plugin of options.plugins) { + if (plugin.processReleases) await plugin.processReleases(releases) + } + return releases.filter(filterReleases(options)) } diff --git a/src/run.js b/src/run.js index 95e30b28..5f3cba04 100644 --- a/src/run.js +++ b/src/run.js @@ -1,4 +1,5 @@ const { Command } = require('commander') +const importCwd = require('import-cwd') const { version } = require('../package.json') const { fetchRemote } = require('./remote') const { fetchTags } = require('./tags') @@ -16,7 +17,8 @@ const DEFAULT_OPTIONS = { sortCommits: 'relevance', appendGitLog: '', appendGitTag: '', - config: '.auto-changelog' + config: '.auto-changelog', + plugins: [] } const PACKAGE_FILE = 'package.json' @@ -58,6 +60,7 @@ const getOptions = async argv => { .option('--append-git-tag ', 'string to append to git tag command') .option('--prepend', 'prepend changelog to output file') .option('--stdout', 'output changelog to stdout') + .option('--plugins [name...]', 'use plugins to augment commit/merge/release information') .version(version) .parse(argv) .opts() @@ -76,7 +79,8 @@ const getOptions = async argv => { return { ...options, ...remote, - latestVersion + latestVersion, + plugins: options.plugins.map(p => importCwd(`auto-changelog-${p}`)) } } diff --git a/yarn.lock b/yarn.lock index 1ed0c869..ae9e238e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1377,6 +1377,13 @@ ignore@~5.1.9: resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.9.tgz#9ec1a5cbe8e1446ec60d4420060d43aa6e7382fb" integrity sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ== +import-cwd@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-3.0.0.tgz#20845547718015126ea9b3676b7592fb8bd4cf92" + integrity sha512-4pnzH16plW+hgvRECbDWpQl3cqtvSofHWh44met7ESfZ8UZOWWddm8hEyDTqREJ9RbYHY8gi8DqmaelApoOGMg== + dependencies: + import-from "^3.0.0" + import-fresh@^3.0.0, import-fresh@^3.2.1: version "3.3.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b" @@ -1385,6 +1392,13 @@ import-fresh@^3.0.0, import-fresh@^3.2.1: parent-module "^1.0.0" resolve-from "^4.0.0" +import-from@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/import-from/-/import-from-3.0.0.tgz#055cfec38cd5a27d8057ca51376d7d3bf0891966" + integrity sha512-CiuXOFFSzkU5x/CR0+z7T91Iht4CXgfCxVOFRhh2Zyhg5wOpWvvDLQUsWl+gcN+QscYBjez8hDCt85O7RLDttQ== + dependencies: + resolve-from "^5.0.0" + imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"