Skip to content

Instantly share code, notes, and snippets.

@shapiy
Created October 12, 2021 12:41
Show Gist options
  • Save shapiy/b1fa5d2d8d390dcd16299dfb1346de6c to your computer and use it in GitHub Desktop.
Save shapiy/b1fa5d2d8d390dcd16299dfb1346de6c to your computer and use it in GitHub Desktop.
standard-version updater for Leiningen project.clj
// 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