Version bumping script fixes #19
|
@ -1,44 +1,43 @@
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
version = input("New version = ").strip()
|
version_input = input("New version = ").strip()
|
||||||
|
|
||||||
js_file = Path("melpomene.js")
|
js_file = Path("melpomene.js")
|
||||||
css_file = Path("melpomene.css")
|
css_file = Path("melpomene.css")
|
||||||
js_css_match = r"(?<=/\* Version ).*(?= \*/)"
|
JS_CSS_MATCH = r"(?<=/\* Version ).*(?= \*/)"
|
||||||
|
JS_VARIABLE_MATCH = r"(?<=const MELPOMENE_VERSION = \").*(?=\";)"
|
||||||
js_variable_match = r"(?<=const MELPOMENE_VERSION = \").*(?=\";)"
|
|
||||||
|
|
||||||
html_file = Path("melpomene.html")
|
html_file = Path("melpomene.html")
|
||||||
demo_high_res_file = Path("demos/pepper_and_carrot_e35_highres.html")
|
demo_high_res_file = Path("demos/pepper_and_carrot_e35_highres.html")
|
||||||
demo_low_res_file = Path("demos/pepper_and_carrot_e35_lowres.html")
|
demo_low_res_file = Path("demos/pepper_and_carrot_e35_lowres.html")
|
||||||
html_match = r"(?<=<!-- Version ).*(?= -->)"
|
HTML_MATCH = r"(?<=<!-- Version ).*(?= -->)"
|
||||||
|
|
||||||
zoom_generator_file = Path("zooms_generator.py")
|
zoom_generator_file = Path("zooms_generator.py")
|
||||||
zoom_generator_match = r"(?<=# Version ).*(?=$)"
|
ZOOM_GENERATOR_MATCH = r"(?<=# Version ).*(?=$)"
|
||||||
|
|
||||||
|
|
||||||
def replace_version(version, file_path, matcher):
|
def replace_version(version, file_path, matcher):
|
||||||
with open(file=file_path, mode="r", encoding="UTF8") as file:
|
with open(file=file_path, mode="r", encoding="UTF8") as file:
|
||||||
file_data = file.read()
|
file_data = file.read()
|
||||||
|
|
||||||
file_data = re.sub(matcher, version, file_data)
|
file_data = re.sub(matcher, version, file_data, flags=re.MULTILINE)
|
||||||
|
|
||||||
with open(file=file_path, mode="w", encoding="UTF8") as file:
|
with open(file=file_path, mode="w", encoding="UTF8") as file:
|
||||||
file.write(file_data)
|
file.write(file_data)
|
||||||
|
|
||||||
|
|
||||||
if re.match(r"[.a-zA-Z\ \-0-9]{1,30}", version):
|
if re.match(r"[.a-zA-Z\ \-0-9]{1,30}", version_input):
|
||||||
replace_version(version, js_file, js_css_match)
|
replace_version(version_input, js_file, JS_CSS_MATCH)
|
||||||
replace_version(version, js_file, js_variable_match)
|
replace_version(version_input, js_file, JS_VARIABLE_MATCH)
|
||||||
|
|
||||||
replace_version(version, css_file, js_css_match)
|
replace_version(version_input, css_file, JS_CSS_MATCH)
|
||||||
|
|
||||||
replace_version(version, html_file, html_match)
|
replace_version(version_input, html_file, HTML_MATCH)
|
||||||
replace_version(version, demo_high_res_file, html_match)
|
replace_version(version_input, demo_high_res_file, HTML_MATCH)
|
||||||
replace_version(version, demo_low_res_file, html_match)
|
replace_version(version_input, demo_low_res_file, HTML_MATCH)
|
||||||
|
|
||||||
replace_version(version, zoom_generator_file, zoom_generator_match)
|
replace_version(version_input, zoom_generator_file, ZOOM_GENERATOR_MATCH)
|
||||||
|
|
||||||
print("Done")
|
print("Done")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue