Skip to content

Commit 37cdfed

Browse files
mansonacookpete
andauthored
Add a Plugin system (#237)
* add import-cwd dependency * add --plugin option to cli * call plugins functions during parseReleases * Tidy up --------- Co-authored-by: Pete Cook <[email protected]>
1 parent 91226a7 commit 37cdfed

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Options:
5454
--append-git-tag [string] # string to append to git tag command
5555
--prepend # prepend changelog to output file
5656
--stdout # output changelog to stdout
57+
--plugins [...name] # use plugins to augment commit/merge/release information
5758
-V, --version # output the version number
5859
-h, --help # output usage information
5960

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"dependencies": {
4646
"commander": "^7.2.0",
4747
"handlebars": "^4.7.7",
48+
"import-cwd": "^3.0.0",
4849
"node-fetch": "^2.6.1",
4950
"parse-github-url": "^1.0.2",
5051
"semver": "^7.3.5"

src/releases.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ const parseReleases = async (tags, options, onParsed) => {
99
const commits = await fetchCommits(tag.diff, options)
1010
const merges = commits.filter(commit => commit.merge).map(commit => commit.merge)
1111
const fixes = commits.filter(commit => commit.fixes).map(commit => ({ fixes: commit.fixes, commit }))
12+
13+
for (const plugin of options.plugins) {
14+
if (plugin.processCommits) await plugin.processCommits(commits)
15+
if (plugin.processMerges) await plugin.processMerges(merges)
16+
if (plugin.processFixes) await plugin.processFixes(merges)
17+
}
18+
1219
const emptyRelease = merges.length === 0 && fixes.length === 0
1320
const { message } = commits[0] || { message: null }
1421
const breakingCount = commits.filter(c => c.breaking).length
@@ -27,6 +34,11 @@ const parseReleases = async (tags, options, onParsed) => {
2734
fixes
2835
}
2936
}))
37+
38+
for (const plugin of options.plugins) {
39+
if (plugin.processReleases) await plugin.processReleases(releases)
40+
}
41+
3042
return releases.filter(filterReleases(options))
3143
}
3244

src/run.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const { Command } = require('commander')
2+
const importCwd = require('import-cwd')
23
const { version } = require('../package.json')
34
const { fetchRemote } = require('./remote')
45
const { fetchTags } = require('./tags')
@@ -16,7 +17,8 @@ const DEFAULT_OPTIONS = {
1617
sortCommits: 'relevance',
1718
appendGitLog: '',
1819
appendGitTag: '',
19-
config: '.auto-changelog'
20+
config: '.auto-changelog',
21+
plugins: []
2022
}
2123

2224
const PACKAGE_FILE = 'package.json'
@@ -58,6 +60,7 @@ const getOptions = async argv => {
5860
.option('--append-git-tag <string>', 'string to append to git tag command')
5961
.option('--prepend', 'prepend changelog to output file')
6062
.option('--stdout', 'output changelog to stdout')
63+
.option('--plugins [name...]', 'use plugins to augment commit/merge/release information')
6164
.version(version)
6265
.parse(argv)
6366
.opts()
@@ -76,7 +79,8 @@ const getOptions = async argv => {
7679
return {
7780
...options,
7881
...remote,
79-
latestVersion
82+
latestVersion,
83+
plugins: options.plugins.map(p => importCwd(`auto-changelog-${p}`))
8084
}
8185
}
8286

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,13 @@ ignore@~5.1.9:
13771377
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.9.tgz#9ec1a5cbe8e1446ec60d4420060d43aa6e7382fb"
13781378
integrity sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==
13791379

1380+
import-cwd@^3.0.0:
1381+
version "3.0.0"
1382+
resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-3.0.0.tgz#20845547718015126ea9b3676b7592fb8bd4cf92"
1383+
integrity sha512-4pnzH16plW+hgvRECbDWpQl3cqtvSofHWh44met7ESfZ8UZOWWddm8hEyDTqREJ9RbYHY8gi8DqmaelApoOGMg==
1384+
dependencies:
1385+
import-from "^3.0.0"
1386+
13801387
import-fresh@^3.0.0, import-fresh@^3.2.1:
13811388
version "3.3.0"
13821389
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:
13851392
parent-module "^1.0.0"
13861393
resolve-from "^4.0.0"
13871394

1395+
import-from@^3.0.0:
1396+
version "3.0.0"
1397+
resolved "https://registry.yarnpkg.com/import-from/-/import-from-3.0.0.tgz#055cfec38cd5a27d8057ca51376d7d3bf0891966"
1398+
integrity sha512-CiuXOFFSzkU5x/CR0+z7T91Iht4CXgfCxVOFRhh2Zyhg5wOpWvvDLQUsWl+gcN+QscYBjez8hDCt85O7RLDttQ==
1399+
dependencies:
1400+
resolve-from "^5.0.0"
1401+
13881402
imurmurhash@^0.1.4:
13891403
version "0.1.4"
13901404
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

0 commit comments

Comments
 (0)