Skip to content

Commit

Permalink
feat: allows configuration of standard-version and submodules using p…
Browse files Browse the repository at this point in the history
…ackage.json or a provided --config file

see #169, #154
  • Loading branch information
Joe Bottigliero committed Nov 22, 2018
1 parent 844cde6 commit db70dc6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
31 changes: 28 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ const changelog = require('./lib/lifecycles/changelog')
const commit = require('./lib/lifecycles/commit')
const tag = require('./lib/lifecycles/tag')

// allows configuration of `standard-version` and submodules via `standard-version`
// key in `package.json` or a provided `--config` file.
function getConfigurationFromArguments (argv) {
const hasConfigArg = Boolean(argv.config)
const configurationPath = path.resolve(process.cwd(), hasConfigArg ? argv.config : 'package.json')
const config = require(configurationPath)
if (typeof config === 'function') {
// if the export of the configuraiton is a function, we expect the
// result to be our configuration object.
return config()
}
if (typeof config === 'object') {
return !hasConfigArg || config.hasOwnProperty('standard-version') ? (config['standard-version'] || {}) : config
}
return {}
}

module.exports = function standardVersion (argv) {
let pkg
bump.pkgFiles.forEach((filename) => {
Expand All @@ -18,8 +35,12 @@ module.exports = function standardVersion (argv) {
})
let newVersion
let defaults = require('./defaults')
let args = Object.assign({}, defaults, argv)

const packageConfiguration = getConfigurationFromArguments(argv)
// the `modules` key is reserved for submodule configurations.
const moduleConfigurations = packageConfiguration.modules || {}
// module specific configurations are *not* passed as part of `standard-version`s arguments.
delete packageConfiguration.modules
const args = Object.assign({}, defaults, argv, packageConfiguration)
return Promise.resolve()
.then(() => {
if (!pkg && args.gitTagFallback) {
Expand All @@ -34,7 +55,11 @@ module.exports = function standardVersion (argv) {
newVersion = version
})
.then(() => {
return bump(args, newVersion)
return bump(
args,
newVersion,
moduleConfigurations['conventional-recommended-bump']
)
})
.then((_newVersion) => {
// if bump runs, it calculaes the new version that we
Expand Down
25 changes: 14 additions & 11 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const runLifecycleScript = require('../run-lifecycle-script')
const semver = require('semver')
const writeFile = require('../write-file')

var configsToUpdate = {}
let configsToUpdate = {}
let moduleConfiguration = {}

function Bump (args, version) {
function Bump (args, version, configuration) {
// reset the cache of updated config files each
// time we perform the version bump step.
configsToUpdate = {}

moduleConfiguration = configuration || {}
if (args.skip.bump) return Promise.resolve()
var newVersion = version
let newVersion = version
return runLifecycleScript(args, 'prerelease')
.then(runLifecycleScript.bind(this, args, 'prebump'))
.then((stdout) => {
Expand All @@ -28,7 +29,7 @@ function Bump (args, version) {
})
.then((release) => {
if (!args.firstRelease) {
var releaseType = getReleaseType(args.prerelease, release.releaseType, version)
let releaseType = getReleaseType(args.prerelease, release.releaseType, version)
newVersion = semver.valid(releaseType) || semver.inc(version, releaseType, args.prerelease)
updateConfigs(args, newVersion)
} else {
Expand Down Expand Up @@ -132,12 +133,14 @@ function bumpVersion (releaseAs, callback) {
releaseType: releaseAs
})
} else {
conventionalRecommendedBump({
preset: 'angular'
}, function (err, release) {
if (err) return reject(err)
else return resolve(release)
})
conventionalRecommendedBump(
Object.assign({
preset: 'angular'
}, moduleConfiguration),
function (err, release) {
if (err) return reject(err)
else return resolve(release)
})
}
})
}
Expand Down

0 comments on commit db70dc6

Please sign in to comment.