fix: Empty version files

releases/v3
Jayrgo 2020-08-10 17:11:18 +02:00
parent 63d0e46a0b
commit 091fdfc6a5
No known key found for this signature in database
GPG Key ID: 498EE77E1F8E0A1E
4 changed files with 15 additions and 32 deletions

View File

@ -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') : ''
}
/**

View File

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

View File

@ -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,
)
// Update the file
if (oldVersion) {
// Get the name of where the version is in
const versionName = this.versionPath.split('.').pop()
// Update the file
if (fileContent) {
this.update(
// We use replace instead of yaml.stringify so we can preserve white spaces and comments
fileContent.replace(

View File

@ -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,
)
// Update the file
if (oldVersion) {
// Get the name of where the version is in
const versionName = this.versionPath.split('.').pop()
// Update the file
if (fileContent) {
this.update(
// We use replace instead of yaml.stringify so we can preserve white spaces and comments
fileContent.replace(