fix: Empty version files
parent
63d0e46a0b
commit
091fdfc6a5
|
@ -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')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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(
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue