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.
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const semverRegex = /version[" ]*=[ ]*["'](.*)["']/i | ||
|
||
const getVersionIndex = function (lines) { | ||
let version | ||
const lineNumber = lines.findIndex(line => { | ||
const found = line.match(semverRegex) | ||
if (found == null) { | ||
return false | ||
} | ||
version = found[1] | ||
return true | ||
}) | ||
return { version, lineNumber } | ||
} | ||
|
||
module.exports.readVersion = function (contents) { | ||
const lines = contents.split('\n') | ||
const versionIndex = getVersionIndex(lines) | ||
return versionIndex.version | ||
} | ||
|
||
module.exports.writeVersion = function (contents, version) { | ||
const lines = contents.split('\n') | ||
const versionIndex = getVersionIndex(lines) | ||
const versionLine = lines[versionIndex.lineNumber] | ||
const newVersionLine = versionLine.replace(versionIndex.version, version) | ||
lines[versionIndex.lineNumber] = newVersionLine | ||
return lines.join('\n') | ||
} |
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,12 @@ | ||
[tool.poetry] | ||
name = "test" | ||
version = "1.0.0" | ||
description = "" | ||
authors = [] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
|
||
[build-system] | ||
requires = ["poetry>=1"] | ||
build-backend = "poetry.masonry.api" |
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,12 @@ | ||
[tool.poetry] | ||
name = "test" | ||
version = "1.1.0" | ||
description = "" | ||
authors = [] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
|
||
[build-system] | ||
requires = ["poetry>=1"] | ||
build-backend = "poetry.masonry.api" |