Created
October 12, 2021 12:41
-
-
Save shapiy/b1fa5d2d8d390dcd16299dfb1346de6c to your computer and use it in GitHub Desktop.
standard-version updater for Leiningen project.clj
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
// standard-version updater to read and write project version from/to Leiningen project.clj. | |
const defProjectRegex = /\(defproject\s+([a-z\./-]+)\s+\"([^\"]+)\".*/; | |
module.exports = { | |
bumpFiles: [{ | |
filename: 'project.clj', | |
updater: { | |
readVersion: function(contents) { | |
const lines = contents.split("\n"); | |
const defProject = lines[0]; | |
match = defProjectRegex.exec(defProject) | |
if (match === null) { | |
throw new Error('Cannot read version from project.clj'); | |
} | |
return match[2]; | |
}, | |
writeVersion: function(contents, version) { | |
const lines = contents.split("\n"); | |
const defProject = lines[0]; | |
const defProjectUpdated = defProject.replace( | |
defProjectRegex, | |
"(defproject $1 \"" + version + "\"" | |
); | |
if (defProject.trim() == defProjectUpdated.trim()) { | |
console.warn('Failed to update project.clj. Contents are identical!'); | |
} | |
lines[0] = defProjectUpdated; | |
return lines.join("\n"); | |
} | |
} | |
}] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment