Skip to content

Commit

Permalink
feat: Support custom updater as object as well as path
Browse files Browse the repository at this point in the history
  • Loading branch information
Eemeli Aro committed Jul 23, 2020
1 parent 9110044 commit 80e5d74
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -355,7 +355,7 @@ As of version `7.1.0` you can configure multiple `bumpFiles` and `packageFiles`.

1. Specify a custom `bumpFile` "`filename`", this is the path to the file you want to "bump"
2. Specify the `bumpFile` "`updater`", this is _how_ the file will be bumped.

a. If your using a common type, you can use one of `standard-version`'s built-in `updaters` by specifying a `type`.

b. If your using an less-common version file, you can create your own `updater`.
Expand Down Expand Up @@ -383,6 +383,21 @@ As of version `7.1.0` you can configure multiple `bumpFiles` and `packageFiles`.
}
```

If using `.versionrc.js` as your configuration file, the `updater` may also be set as an object, rather than a path:

```js
// .versionrc.js
const tracker = {
filename: 'VERSION_TRACKER.json',
updater: require('./path/to/custom-version-updater')
}

module.exports = {
bumpFiles: [tracker],
packageFiles: [tracker]
}
```

#### Custom `updater`s

An `updater` is expected to be a Javascript module with _atleast_ two methods exposed: `readVersion` and `writeVersion`.
Expand Down
11 changes: 10 additions & 1 deletion lib/updaters/index.js
Expand Up @@ -23,7 +23,16 @@ function getUpdaterByFilename (filename) {
}

function getCustomUpdater (updater) {
return require(path.resolve(process.cwd(), updater))
if (typeof updater === 'string') {
return require(path.resolve(process.cwd(), updater))
}
if (
typeof updater.readVersion === 'function' &&
typeof updater.writeVersion === 'function'
) {
return updater
}
throw new Error('Updater must be a string path or an object with readVersion and writeVersion methods')
}

module.exports.resolveUpdaterObjectFromArgument = function (arg) {
Expand Down

0 comments on commit 80e5d74

Please sign in to comment.