feat: Added support for toml files

releases/v3
Tycho Bokdam 2020-07-03 21:55:40 +02:00
parent bdf8ec04e6
commit 5aff23f514
No known key found for this signature in database
GPG Key ID: A0FAE77C8CDF33C7
3 changed files with 50 additions and 0 deletions

View File

@ -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

View File

@ -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}"`,
),
)
}
})

6
test-file.toml 100644
View File

@ -0,0 +1,6 @@
title = "test"
# Comment
[package]
name = "test file"
version = "0.1.0"