diff --git a/src/version/index.js b/src/version/index.js index edaa5b1..2d3a1a8 100644 --- a/src/version/index.js +++ b/src/version/index.js @@ -1,6 +1,7 @@ const JSON = require('./json') const Git = require('./git') const Yaml = require('./yaml') +const Toml = require('./toml') module.exports = (fileExtension) => { switch (fileExtension.toLowerCase()) { @@ -10,6 +11,8 @@ module.exports = (fileExtension) => { case 'yml': return Yaml + case 'toml': + return Toml case 'git': return Git diff --git a/src/version/toml.js b/src/version/toml.js new file mode 100644 index 0000000..e164e38 --- /dev/null +++ b/src/version/toml.js @@ -0,0 +1,41 @@ +const objectPath = require('object-path') +const toml = require('toml') + +const BaseVersioning = require('./base') +const bumpVersion = require('../helpers/bumpVersion') + +module.exports = new (class Toml extends BaseVersioning{ + + /** + * Bumps the version in the package.json + * + * @param {!string} releaseType - The type of release + * @return {*} + */ + bump = (releaseType) => { + // Read the file + const fileContent = this.read() + const tomlContent = toml.parse(fileContent) + const oldVersion = objectPath.get(tomlContent, this.versionPath) + + // Get the new version + this.newVersion = bumpVersion( + releaseType, + oldVersion, + ) + + // Get the name of where the version is in + const versionName = this.versionPath.split('.').pop() + + // Update the file + this.update( + // We use replace so we can preserve white spaces and comments + fileContent.replace( + `${versionName} = "${oldVersion}"`, + `${versionName} = "${this.newVersion}"`, + ), + ) + } + +}) + diff --git a/test-file.toml b/test-file.toml new file mode 100644 index 0000000..5d4eb44 --- /dev/null +++ b/test-file.toml @@ -0,0 +1,6 @@ +title = "test" + +# Comment +[package] +name = "test file" +version = "0.1.0"