Skip to content

Commit

Permalink
fix: adds conventional-changelog-core option handling
Browse files Browse the repository at this point in the history
- The `changelog` lifecyle now passes along `conventional-changelog` configuration as `options` and `conventional-changelog-core` configuration as `context`.
- Updates the passing of configurations to lifecycles to be consistent (the entire `modules` object).
- Adds tests to cover `conventional-changelog-core` options, `--tagPrefix` and a few permutations.
  • Loading branch information
jbottigliero committed Feb 22, 2019
1 parent 980c3a1 commit fef7f82
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = function standardVersion (argv) {
return bump(
args,
newVersion,
moduleConfigurations['conventional-recommended-bump']
moduleConfigurations
)
})
.then((_newVersion) => {
Expand All @@ -52,7 +52,7 @@ module.exports = function standardVersion (argv) {
return changelog(
args,
newVersion,
moduleConfigurations['conventional-changelog']
moduleConfigurations
)
})
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Bump (args, version, configuration) {
// reset the cache of updated config files each
// time we perform the version bump step.
configsToUpdate = {}
moduleConfiguration = configuration || {}
moduleConfiguration = configuration['conventional-recommended-bump'] || {}
if (args.skip.bump) return Promise.resolve()
let newVersion = version
return runLifecycleScript(args, 'prerelease')
Expand Down
17 changes: 9 additions & 8 deletions lib/lifecycles/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ const fs = require('fs')
const runLifecycleScript = require('../run-lifecycle-script')
const writeFile = require('../write-file')

module.exports = function (args, newVersion, moduleConfiguration) {
module.exports = function (args, newVersion, moduleConfigurations) {
if (args.skip.changelog) return Promise.resolve()
return runLifecycleScript(args, 'prechangelog')
.then(() => {
return outputChangelog(args, newVersion, moduleConfiguration)
return outputChangelog(args, newVersion, moduleConfigurations)
})
.then(() => {
return runLifecycleScript(args, 'postchangelog')
})
}

function outputChangelog (args, newVersion, moduleConfiguration) {
function outputChangelog (args, newVersion, moduleConfigurations) {
return new Promise((resolve, reject) => {
createIfMissing(args)
var header = '# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n'
Expand All @@ -27,19 +27,20 @@ function outputChangelog (args, newVersion, moduleConfiguration) {
oldContent = oldContent.substring(oldContent.indexOf('<a name='))
}
var content = ''
var context
if (args.dryRun) context = { version: newVersion }
var context = {}
if (args.dryRun) context.version = newVersion
Object.assign(context, moduleConfigurations['conventional-changelog-core'])

var config = Object.assign({}, {
debug: args.verbose && console.info.bind(console, 'conventional-changelog'),
preset: args.preset || 'angular',
tagPrefix: args.tagPrefix,
...moduleConfiguration
tagPrefix: args.tagPrefix
})
Object.assign(config, moduleConfigurations['conventional-changelog'])

var changelogStream = conventionalChangelog(
config,
{ ...context, ...moduleConfiguration },
context,
{ merges: null, path: args.path }
).on('error', function (err) {
return reject(err)
Expand Down
58 changes: 48 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('cli', function () {
execCli('--preset ' + presetOverride).code.should.equal(0)
assertPresetOverrideCHANGELOG()
})
it('via package.json (["standard-version"].modules.["conventional-changelog"].preset)', function () {
it('via package.json (["standard-version"].modules["conventional-changelog"].preset)', function () {
writePackageJson('1.0.0', {
'standard-version': {
modules: {
Expand All @@ -161,7 +161,7 @@ describe('cli', function () {
execCli().code.should.equal(0)
assertPresetOverrideCHANGELOG()
})
it('via custom.json (modules.["conventional-changelog"].preset)', function () {
it('via custom.json (modules["conventional-changelog"].preset)', function () {
fs.writeFileSync('custom.json', JSON.stringify({
modules: {
'conventional-changelog': {
Expand All @@ -173,7 +173,7 @@ describe('cli', function () {
execCli('--config custom.json').code.should.equal(0)
assertPresetOverrideCHANGELOG()
})
it('via functional-config.js (modules.["conventional-changelog"].preset)', function () {
it('via functional-config.js (modules["conventional-changelog"].preset)', function () {
fs.writeFileSync(
'functional-config.js',
`module.exports = () => ({
Expand All @@ -189,12 +189,33 @@ describe('cli', function () {
execCli('--config functional-config.js').code.should.equal(0)
assertPresetOverrideCHANGELOG()
})
it('allows modules["conventional-changelog"].preset and modules["conventional-changelog-core"] options', function () {
writePackageJson('2.0.0', {
'standard-version': {
modules: {
'conventional-changelog': {
preset: presetOverride
},
'conventional-changelog-core': {
host: 'gitlab',
repoUrl: 'https://other-git-service.com/repoUrl',
repository: 'git+https://other-git-service.com/repository.git'
}
}
}
})
makePresetCommits()
execCli().code.should.equal(0)
assertPresetOverrideCHANGELOG()
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.contain('other-git-service.com')
})
})
it('allows configuration of repository options', function () {
it('allows configuration of repository options (modules.["conventional-changelog-core"])', function () {
writePackageJson('2.0.0', {
'standard-version': {
modules: {
'conventional-changelog': {
'conventional-changelog-core': {
host: 'gitlab',
repoUrl: 'https://other-git-service.com/repoUrl',
repository: 'git+https://other-git-service.com/repository.git'
Expand All @@ -205,13 +226,30 @@ describe('cli', function () {
commit('feat: angular style commit with issue reference\n\n#278')
execCli().code.should.equal(0)
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
/**
* @todo this test fails. it seems like it could actually be an issue with
* `conventional-changelog/conventional-changelog-core`, _or_ a configuration
* value is missing.
*/
content.should.contain('other-git-service.com')
})

describe('tagPrefix', function () {
it('via --tagPrefix flag', function () {
var prefix = 'version-foo/'
commit('feat: angular style commit')
execCli('--tagPrefix=' + prefix).code.should.equal(0)
commit('feat: another angular style commit')
execCli('--tagPrefix=' + prefix).code.should.equal(0)
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.contain('/compare/' + prefix)
})

it('via --tagPrefix flag with --preset flag', function () {
var prefix = 'version-foo/'
commit('Feat: eslint style commit')
execCli('--preset=eslint --tagPrefix=' + prefix).code.should.equal(0)
commit('Feat: another eslint style commit')
execCli('--preset=eslint --tagPrefix=' + prefix).code.should.equal(0)
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content.should.contain('/compare/' + prefix)
})
})
})

describe('CHANGELOG.md does not exist', function () {
Expand Down

0 comments on commit fef7f82

Please sign in to comment.