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

View File

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