fix: Empty version files
parent
63d0e46a0b
commit
091fdfc6a5
|
@ -25,9 +25,7 @@ module.exports = class BaseVersioning {
|
|||
* @return {string}
|
||||
*/
|
||||
read = () => {
|
||||
if (fs.existsSync(this.fileLocation)) {
|
||||
return fs.readFileSync(this.fileLocation, 'utf8')
|
||||
}
|
||||
return fs.existsSync(this.fileLocation) ? fs.readFileSync(this.fileLocation, 'utf8') : ''
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,15 +12,10 @@ module.exports = new (class Json extends BaseVersioning {
|
|||
* @return {*}
|
||||
*/
|
||||
bump = (releaseType) => {
|
||||
let jsonContent = {}
|
||||
let oldVersion
|
||||
|
||||
// Read the file
|
||||
const fileContent = this.read()
|
||||
if (fileContent) {
|
||||
jsonContent = JSON.parse(fileContent)
|
||||
oldVersion = objectPath.get(jsonContent, this.versionPath)
|
||||
}
|
||||
const jsonContent = JSON.parse(fileContent)
|
||||
const oldVersion = objectPath.get(jsonContent, this.versionPath, null)
|
||||
|
||||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
|
|
|
@ -13,15 +13,10 @@ module.exports = new (class Toml extends BaseVersioning{
|
|||
* @return {*}
|
||||
*/
|
||||
bump = (releaseType) => {
|
||||
let tomlContent = {}
|
||||
let oldVersion
|
||||
|
||||
// Read the file
|
||||
const fileContent = this.read()
|
||||
if (fileContent) {
|
||||
tomlContent = toml.parse(fileContent)
|
||||
oldVersion = objectPath.get(tomlContent, this.versionPath)
|
||||
}
|
||||
const tomlContent = toml.parse(fileContent)
|
||||
const oldVersion = objectPath.get(tomlContent, this.versionPath, null)
|
||||
|
||||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
|
@ -29,11 +24,11 @@ module.exports = new (class Toml extends BaseVersioning{
|
|||
oldVersion,
|
||||
)
|
||||
|
||||
// Get the name of where the version is in
|
||||
const versionName = this.versionPath.split('.').pop()
|
||||
|
||||
// Update the file
|
||||
if (fileContent) {
|
||||
if (oldVersion) {
|
||||
// Get the name of where the version is in
|
||||
const versionName = this.versionPath.split('.').pop()
|
||||
|
||||
this.update(
|
||||
// We use replace instead of yaml.stringify so we can preserve white spaces and comments
|
||||
fileContent.replace(
|
||||
|
|
|
@ -13,15 +13,10 @@ module.exports = new (class Yaml extends BaseVersioning{
|
|||
* @return {*}
|
||||
*/
|
||||
bump = (releaseType) => {
|
||||
let yamlContent = {}
|
||||
let oldVersion
|
||||
|
||||
// Read the file
|
||||
const fileContent = this.read()
|
||||
if (fileContent) {
|
||||
yamlContent = yaml.parse(fileContent)
|
||||
oldVersion = objectPath.get(yamlContent, this.versionPath)
|
||||
}
|
||||
const yamlContent = yaml.parse(fileContent) || {}
|
||||
const oldVersion = objectPath.get(yamlContent, this.versionPath, null)
|
||||
|
||||
// Get the new version
|
||||
this.newVersion = bumpVersion(
|
||||
|
@ -29,11 +24,11 @@ module.exports = new (class Yaml extends BaseVersioning{
|
|||
oldVersion,
|
||||
)
|
||||
|
||||
// Get the name of where the version is in
|
||||
const versionName = this.versionPath.split('.').pop()
|
||||
|
||||
// Update the file
|
||||
if (fileContent) {
|
||||
if (oldVersion) {
|
||||
// Get the name of where the version is in
|
||||
const versionName = this.versionPath.split('.').pop()
|
||||
|
||||
this.update(
|
||||
// We use replace instead of yaml.stringify so we can preserve white spaces and comments
|
||||
fileContent.replace(
|
||||
|
|
Loading…
Reference in New Issue