Compare commits

..

No commits in common. "main" and "0.1.0" have entirely different histories.
main ... 0.1.0

3 changed files with 22 additions and 28 deletions

2
.gitignore vendored
View File

@ -1,2 +0,0 @@
.*sw?
update_nim_package_version

View File

@ -1,37 +1,37 @@
import os, strutils, unicode
import nre except toSeq
type VersionInfo = tuple[curVersion, nextVersion, varName: string]
let NIMBLE_VERSION_REGEX = re"(\s*version\s*=\s*).*"
let VERSION_ASSIGNMENT_REGEX = re(r"(\s*)const (\S*VERSION\S*)\s*=\s*""([^""]+)""")
type VersionInfo = tuple[curVersion, nextVersion, assignment: string]
proc getCurVersion(versionFilename: string): VersionInfo =
let verPat = re(r"(.*=\s*)""([\d.]+)""")
for line in versionFilename.lines:
let m = line.match(VERSION_ASSIGNMENT_REGEX)
let m = line.match(verPat)
if m.isSome:
return (
curVersion: m.get.captures[2],
nextVersion: m.get.captures[2],
varName: m.get.captures[1])
curVersion: m.get.captures[1],
nextVersion: m.get.captures[1],
assignment: m.get.captures[0])
raise newException(Exception, "Could not find the current version in " & versionFilename)
proc updateVersionInFile(file: string, versionInfo: VersionInfo): void =
proc updateVersionFile(versionFilename: string, versionInfo: VersionInfo): void =
versionFilename.writeFile(versionInfo.assignment & "\"" & versionInfo.nextVersion & "\"")
proc updateNimbleFile(projectName: string, versionInfo: VersionInfo): void =
var newLines: seq[string] = @[]
let verPat = re"(\s*version\s*=\s*).*"
let nimbleFilename = projectName & ".nimble"
for line in file.lines:
let m1 = line.match(NIMBLE_VERSION_REGEX)
let m2 = line.match(VERSION_ASSIGNMENT_REGEX)
if m1.isSome:
newLines.add(m1.get.captures[0] & '"' & versionInfo.nextVersion & '"')
elif m2.isSome:
newLines.add(m2.get.captures[0] & "const " & m2.get.captures[1] & " = \"" & versionInfo.nextVersion & '"')
for line in nimbleFilename.lines:
let m = line.match(verPat)
if m.isSome:
newLines.add(m.get.captures[0] & '"' & versionInfo.nextVersion & '"')
else: newLines.add(line)
file.writeFile(newLines.join("\n"))
nimbleFilename.writeFile(newLines.join("\n"))
when isMainModule:
if paramCount() < 2:
@ -42,9 +42,9 @@ when isMainModule:
let projectName = paramStr(1)
let versionFilepath = paramStr(2)
var versionInfo = getCurVersion(versionFilepath)
try:
var versionInfo = getCurVersion(versionFilepath)
var acceptNewVersion = false
while not acceptNewVersion:
stdout.writeLine "Current version is " & versionInfo.curVersion & "."
@ -56,16 +56,12 @@ when isMainModule:
acceptNewVersion = "yes".startsWith(isCorrect.toLower)
echo "Updating version definition in " & versionFilepath
updateVersionInFile(versionFilepath, versionInfo)
updateVersionFile(versionFilepath, versionInfo)
echo "Updating version definition in " & projectName & ".nimble"
updateVersionInFile(projectName & ".nimble", versionInfo)
updateNimbleFile(projectName, versionInfo)
except EOFError:
echo "Aborted"
quit()
except:
let ex = getCurrentException()
echo getCurrentExceptionMsg()
echo ex.getStackTrace()

View File

@ -1,6 +1,6 @@
# Package
version = "0.2.0"
version = "0.1.0"
author = "Jonathan Bernard"
description = "Small util to update version consistently for nim packages I write."
license = "MIT"