refactor: use one config object instead of passing arguments to plugins on their own

This commit does a lot but it's all connected and tries to make everything more extensible and future proof.

1. CLI arguments and options from the "package.json" are no longer treated as two different things. You can now pass options either way.

BREAKING CHANGE: cli arguments are now normalized to camelCase, so e.g. `options['github-url']` is now `options.githubUrl`

2. Plugins no longer receive config they need one by one, but in one huge object. This way it's easier to pass more info in the future w/o breaking existing plugins that rely on the position of the callback in the arguments array.

BREAKING CHANGE: Plugins now need to read their passed options from one huge config object.

Old:
```js
module.exports = function (pluginConfig, foo, bar, cb) {…}
```

New:
```js
// ES5
module.exports = function(pluginConfig, config, cb) {
  var foo = config.foo
  var bar = config.bar
  …
}

// ES6
module.exports = function (pluginConfig, {foo, bar}, cb) {…}
```
This commit is contained in:
Stephan Bönnemann
2015-07-19 15:34:30 +02:00
parent 8892ec7f7a
commit d9eeb3fcae
16 changed files with 190 additions and 161 deletions
+14 -12
View File
@@ -7,12 +7,12 @@ test('get type from commits', (t) => {
tt.plan(2)
type({
analyzeCommits: (commits, cb) => cb(null, 'major')
}, [{
hash: '0',
message: 'a'
}], {
version: '1.0.0'
commits: [{
hash: '0',
message: 'a'
}],
lastRelease: {version: '1.0.0'},
plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
}, (err, type) => {
tt.error(err)
tt.is(type, 'major')
@@ -23,9 +23,10 @@ test('get type from commits', (t) => {
tt.plan(1)
type({
analyzeCommits: (commits, cb) => cb(null, null)
}, [], {},
(err) => {
commits: [],
lastRelease: {},
plugins: {analyzeCommits: (config, cb) => cb(null, null)}
}, (err) => {
tt.is(err.code, 'ENOCHANGE')
})
})
@@ -34,9 +35,10 @@ test('get type from commits', (t) => {
tt.plan(2)
type({
analyzeCommits: (commits, cb) => cb(null, 'major')
}, [], {},
(err, type) => {
commits: [],
lastRelease: {},
plugins: {analyzeCommits: (config, cb) => cb(null, 'major')}
}, (err, type) => {
tt.error(err)
tt.is(type, 'initial')
})