forked from conventional-changelog/standard-version
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: added maven support * fix: correct updater for pom.xml files
- Loading branch information
Showing
10 changed files
with
681 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const jsdom = require('jsdom'); | ||
const serialize = require('w3c-xmlserializer'); | ||
const detectNewline = require('detect-newline'); | ||
const CRLF = '\r\n'; | ||
const LF = '\n'; | ||
|
||
function pomDocument(contents) { | ||
const dom = new jsdom.JSDOM(''); | ||
const parser = new dom.window.DOMParser(); | ||
return parser.parseFromString(contents, 'application/xml'); | ||
} | ||
|
||
function pomVersionElement(document) { | ||
const versionElement = document.querySelector('project > version'); | ||
|
||
if (!versionElement) { | ||
throw new Error( | ||
'Failed to read the version field in your pom file - is it present?', | ||
); | ||
} | ||
|
||
return versionElement; | ||
} | ||
|
||
module.exports.readVersion = function (contents) { | ||
const document = pomDocument(contents); | ||
return pomVersionElement(document).textContent; | ||
}; | ||
|
||
module.exports.writeVersion = function (contents, version) { | ||
const newline = detectNewline(contents); | ||
const document = pomDocument(contents); | ||
const versionElement = pomVersionElement(document); | ||
|
||
versionElement.textContent = version; | ||
|
||
const xml = serialize(document); | ||
|
||
if (newline === CRLF) { | ||
return xml.replace(/\n/g, CRLF) + CRLF; | ||
} | ||
|
||
return xml + LF; | ||
}; |
Oops, something went wrong.