feat: Added support for toml files
parent
bdf8ec04e6
commit
5aff23f514
|
@ -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
|
||||
|
|
|
@ -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}"`,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
})
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
title = "test"
|
||||
|
||||
# Comment
|
||||
[package]
|
||||
name = "test file"
|
||||
version = "0.1.0"
|
Loading…
Reference in New Issue