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} * @return {string}
*/ */
read = () => { read = () => {
if (fs.existsSync(this.fileLocation)) { return fs.existsSync(this.fileLocation) ? fs.readFileSync(this.fileLocation, 'utf8') : ''
return fs.readFileSync(this.fileLocation, 'utf8')
}
} }
/** /**

View File

@ -12,15 +12,10 @@ module.exports = new (class Json extends BaseVersioning {
* @return {*} * @return {*}
*/ */
bump = (releaseType) => { bump = (releaseType) => {
let jsonContent = {}
let oldVersion
// Read the file // Read the file
const fileContent = this.read() const fileContent = this.read()
if (fileContent) { const jsonContent = JSON.parse(fileContent)
jsonContent = JSON.parse(fileContent) const oldVersion = objectPath.get(jsonContent, this.versionPath, null)
oldVersion = objectPath.get(jsonContent, this.versionPath)
}
// Get the new version // Get the new version
this.newVersion = bumpVersion( this.newVersion = bumpVersion(

View File

@ -13,15 +13,10 @@ module.exports = new (class Toml extends BaseVersioning{
* @return {*} * @return {*}
*/ */
bump = (releaseType) => { bump = (releaseType) => {
let tomlContent = {}
let oldVersion
// Read the file // Read the file
const fileContent = this.read() const fileContent = this.read()
if (fileContent) { const tomlContent = toml.parse(fileContent)
tomlContent = toml.parse(fileContent) const oldVersion = objectPath.get(tomlContent, this.versionPath, null)
oldVersion = objectPath.get(tomlContent, this.versionPath)
}
// Get the new version // Get the new version
this.newVersion = bumpVersion( this.newVersion = bumpVersion(
@ -29,11 +24,11 @@ module.exports = new (class Toml extends BaseVersioning{
oldVersion, oldVersion,
) )
// Get the name of where the version is in
const versionName = this.versionPath.split('.').pop()
// Update the file // Update the file
if (fileContent) { if (oldVersion) {
// Get the name of where the version is in
const versionName = this.versionPath.split('.').pop()
this.update( this.update(
// We use replace instead of yaml.stringify so we can preserve white spaces and comments // We use replace instead of yaml.stringify so we can preserve white spaces and comments
fileContent.replace( fileContent.replace(

View File

@ -13,15 +13,10 @@ module.exports = new (class Yaml extends BaseVersioning{
* @return {*} * @return {*}
*/ */
bump = (releaseType) => { bump = (releaseType) => {
let yamlContent = {}
let oldVersion
// Read the file // Read the file
const fileContent = this.read() const fileContent = this.read()
if (fileContent) { const yamlContent = yaml.parse(fileContent) || {}
yamlContent = yaml.parse(fileContent) const oldVersion = objectPath.get(yamlContent, this.versionPath, null)
oldVersion = objectPath.get(yamlContent, this.versionPath)
}
// Get the new version // Get the new version
this.newVersion = bumpVersion( this.newVersion = bumpVersion(
@ -29,11 +24,11 @@ module.exports = new (class Yaml extends BaseVersioning{
oldVersion, oldVersion,
) )
// Get the name of where the version is in
const versionName = this.versionPath.split('.').pop()
// Update the file // Update the file
if (fileContent) { if (oldVersion) {
// Get the name of where the version is in
const versionName = this.versionPath.split('.').pop()
this.update( this.update(
// We use replace instead of yaml.stringify so we can preserve white spaces and comments // We use replace instead of yaml.stringify so we can preserve white spaces and comments
fileContent.replace( fileContent.replace(