Merge pull request #202 from skhomuti/fix-eol

Fixed end of file in package.json
releases/v3
Tycho Bokdam 2023-03-02 09:28:27 +01:00 committed by GitHub
commit acd95e2b8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 60 deletions

View File

@ -1,59 +0,0 @@
const path = require('path')
const fs = require('fs')
const core = require('@actions/core')
const packageJsonLoc = path.resolve(core.getInput('package-json'))
module.exports = {
/**
* Get's the project package.json
* @return {any}
*/
get: () => {
return JSON.parse(fs.readFileSync(packageJsonLoc))
},
/**
* Bumps the version in the package.json
*
* @param packageJson
* @param releaseType
* @return {*}
*/
bump: (packageJson, releaseType) => {
let [major, minor, patch] = packageJson.version.split('.')
switch (releaseType) {
case 'major':
major = parseInt(major, 10) + 1
minor = 0
patch = 0
break
case 'minor':
minor = parseInt(minor, 10) + 1
patch = 0
break
default:
patch = parseInt(patch, 10) + 1
}
// Update the package.json with the new version
packageJson.version = `${major}.${minor}.${patch}`
return packageJson
},
/**
* Update package.json
*
* @param packageJson
* @return {*}
*/
update: (packageJson) => (
fs.writeFileSync(packageJsonLoc, JSON.stringify(packageJson, null, 2))
),
}

View File

@ -18,6 +18,7 @@ module.exports = class Json extends BaseVersioning {
// Parse the file // Parse the file
let jsonContent let jsonContent
let eol = fileContent.endsWith('\n') ? '\n' : ''
try { try {
jsonContent = JSON.parse(fileContent) jsonContent = JSON.parse(fileContent)
} catch (error) { } catch (error) {
@ -45,7 +46,7 @@ module.exports = class Json extends BaseVersioning {
// Update the file // Update the file
this.update( this.update(
JSON.stringify(jsonContent, null, 2), JSON.stringify(jsonContent, null, 2) + eol
) )
} }