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.
refactor: use the same implementation pattern as the 'yaml' updater
- Loading branch information
Showing
7 changed files
with
123 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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
const versionRegex = /(^.*?\r?\ninfo:\r?\n.*?version: ")([\d\w\-.]+)(".*?(?=\r?\n\w).*$)/s; | ||
const yaml = require('yaml'); | ||
const detectNewline = require('detect-newline'); | ||
|
||
module.exports.readVersion = function (contents) { | ||
const matches = versionRegex.exec(contents); | ||
if (matches === null || matches.length !== 4) { | ||
throw new Error( | ||
'Failed to read the version field in your openapi file - is it present?', | ||
); | ||
} | ||
return matches[2]; | ||
} | ||
return yaml.parse(contents).info.version; | ||
}; | ||
|
||
module.exports.writeVersion = function (contents, version) { | ||
return contents.replace(versionRegex, `$1${version}$3`); | ||
} | ||
const newline = detectNewline(contents); | ||
const document = yaml.parseDocument(contents); | ||
|
||
document.get('info').set('version', version); | ||
|
||
return document.toString().replace(/\r?\n/g, newline); | ||
}; |
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,15 @@ | ||
const yaml = require('yaml'); | ||
const detectNewline = require('detect-newline'); | ||
|
||
module.exports.readVersion = function (contents) { | ||
return yaml.parse(contents).version; | ||
}; | ||
|
||
module.exports.writeVersion = function (contents, version) { | ||
const newline = detectNewline(contents); | ||
const document = yaml.parseDocument(contents); | ||
|
||
document.set('version', version); | ||
|
||
return document.toString().replace(/\r?\n/g, newline); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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