add deps.edn
This commit is contained in:
parent
ec150dde62
commit
bba684d76e
2 changed files with 35 additions and 2 deletions
|
@ -11,6 +11,7 @@ class BuildFileType(Enum):
|
|||
JS = ".json"
|
||||
JAVA_GRADLE = ".gradle"
|
||||
JAVA_CLOJURE = ".clj"
|
||||
JAVA_CLOJURE_EDN = ".edn"
|
||||
PYTHON = ".py"
|
||||
|
||||
|
||||
|
@ -41,6 +42,8 @@ class BuildFile(Validateable):
|
|||
result = BuildFileType.JAVA_CLOJURE
|
||||
case ".py":
|
||||
result = BuildFileType.PYTHON
|
||||
case ".edn":
|
||||
result = BuildFileType.JAVA_CLOJURE_EDN
|
||||
case _:
|
||||
result = None
|
||||
return result
|
||||
|
@ -53,6 +56,8 @@ class BuildFile(Validateable):
|
|||
return r'(?P<pre_version>\bversion\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"'
|
||||
case BuildFileType.JAVA_CLOJURE:
|
||||
return r'(?P<pre_version>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
case BuildFileType.JAVA_CLOJURE_EDN:
|
||||
return r'(?P<pre_version>\:version\s+)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
case _:
|
||||
return ""
|
||||
|
||||
|
@ -62,7 +67,7 @@ class BuildFile(Validateable):
|
|||
match build_file_type:
|
||||
case BuildFileType.JS:
|
||||
version_str = json.loads(self.content)["version"]
|
||||
case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE:
|
||||
case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE | BuildFileType.JAVA_CLOJURE_EDN:
|
||||
version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version")
|
||||
except:
|
||||
raise RuntimeError(f"Version not found in file {self.file_path}")
|
||||
|
@ -84,7 +89,7 @@ class BuildFile(Validateable):
|
|||
json_data = json.loads(self.content)
|
||||
json_data["version"] = new_version.to_string()
|
||||
self.content = json.dumps(json_data, indent=4)
|
||||
case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE:
|
||||
case BuildFileType.JAVA_GRADLE | BuildFileType.PYTHON | BuildFileType.JAVA_CLOJURE | BuildFileType.JAVA_CLOJURE_EDN:
|
||||
substitute = re.sub(
|
||||
self.__get_file_type_regex_str(build_file_type),
|
||||
fr'\g<pre_version>"{new_version.to_string()}"',
|
||||
|
|
|
@ -183,6 +183,34 @@ def test_should_parse_and_set_version_for_clj():
|
|||
== sut.content
|
||||
)
|
||||
|
||||
def test_should_parse_and_set_version_for_clj_edn():
|
||||
sut = BuildFile(
|
||||
Path("./deps.edn"),
|
||||
"""
|
||||
{:project {:name org.domaindrivenarchitecture/dda-backup
|
||||
:version "1.1.5-SNAPSHOT"}
|
||||
|
||||
}
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT", "SNAPSHOT")
|
||||
|
||||
sut = BuildFile(
|
||||
Path("./deps.edn"),
|
||||
"""
|
||||
{:project {:name org.domaindrivenarchitecture/dda-backup
|
||||
:version "1.1.5-SNAPSHOT"}
|
||||
|
||||
}
|
||||
""",
|
||||
)
|
||||
sut.set_version(Version.from_str("1.1.5-SNAPSHOT", "SNAPSHOT").create_major())
|
||||
assert (
|
||||
'\n{:project {:name org.domaindrivenarchitecture/dda-backup\n :version "2.0.0"}\n\n}\n'
|
||||
== sut.content
|
||||
)
|
||||
|
||||
|
||||
def test_should_throw_for_clj_wrong_version():
|
||||
sut = BuildFile(
|
||||
Path("./project.clj"),
|
||||
|
|
Loading…
Reference in a new issue