Skip to content

Commit

Permalink
fix(preset, conventionalcommits): fix handling conventionalcommits pr…
Browse files Browse the repository at this point in the history
…eset without config object


closes #512
  • Loading branch information
tommywo committed Sep 9, 2019
1 parent 417139c commit c0566ce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/conventional-changelog-cli/test/test.js
Expand Up @@ -367,6 +367,19 @@ describe('cli', function () {
done()
}))
})
it('--preset "conventionalcommits" should work', function (done) {
writeFileSync('angular', '')
shell.exec('git add --all && git commit -m"fix: fix it!"')
var cp = spawn(cliPath, ['--preset', 'conventionalcommits'], {
stdio: [process.stdin, null, null]
})

cp.stdout
.pipe(concat(function (chunk) {
expect(chunk.toString()).to.include('Bug Fixes')
done()
}))
})

it('--config should work with --preset', function (done) {
var cp = spawn(cliPath, ['--preset', 'angular', '--config', path.join(__dirname, 'fixtures/config.js')], {
Expand Down
23 changes: 22 additions & 1 deletion packages/conventional-changelog-conventionalcommits/index.js
@@ -1,11 +1,32 @@
'use strict'
const Q = require(`q`)
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 = function (config) {
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 = {}
// FIXME: use presetOpts(config) for callback
Q.all([
conventionalChangelog(config),
parserOpts(config),
recommendedBumpOpts(config),
writerOpts(config)
]).spread((conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts) => {
parameter(null, { gitRawCommitsOpts: { noMerges: null }, conventionalChangelog, parserOpts, recommendedBumpOpts, writerOpts })
})
} else {
const config = parameter || {}
return presetOpts(config)
}
}

function presetOpts (config) {
return Q.all([
conventionalChangelog(config),
parserOpts(config),
Expand Down
Expand Up @@ -35,6 +35,7 @@
"homepage": "https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular#readme",
"dependencies": {
"compare-func": "^1.3.1",
"lodash": "^4.2.1",
"q": "^1.5.1"
}
}

0 comments on commit c0566ce

Please sign in to comment.