Skip to content

Commit

Permalink
Merge branch 'master' into enh/e2e-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Jan 21, 2025
2 parents 5d655e5 + 00d3690 commit c12285c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
76 changes: 59 additions & 17 deletions services/static-webserver/client/scripts/post-compile.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,83 @@
import os
import json

import os
import random
from pathlib import Path

output_folders = [
"source-output", # dev output
"source-output", # dev output
"build-output", # default production output
"build-client" # I believe we create the production outputs here
"build-client", # I believe we create the production outputs here
]


def read_json_file(filename):
def _get_applications_from_metadata():
dirname = os.path.dirname(__file__)
meta_filename = os.path.join(dirname, filename)
with open(meta_filename, "r") as file:
meta_filename = os.path.join(dirname, "apps_metadata.json")
with open(meta_filename) as file:
metadata = json.load(file)
return metadata["applications"]


def update_apps_metadata():
dirname = os.path.dirname(__file__)
applications = read_json_file("apps_metadata.json")
applications = _get_applications_from_metadata()
for i in applications:
application = i.get("application")
for output_folder in output_folders:
filename = os.path.join(dirname, '..', output_folder, application, "index.html")
if not os.path.isfile(filename):
continue
with open(filename, "r") as file:
data = file.read()
index_file_path = Path(dirname).joinpath(
"..", output_folder, application, "index.html"
)
if os.path.isfile(index_file_path):
print(f"Updating app metadata: {index_file_path.resolve()}")
replacements = i.get("replacements")
for key in replacements:
replace_text = replacements[key]
data = data.replace("${"+key+"}", replace_text)
with open(filename, "w") as file:
print(f"Updating app metadata: {filename}")
file.write(data)
index_file_path.write_text(
index_file_path.read_text().replace(
"${" + key + "}",
replace_text,
)
)


def _get_output_file_paths(filename):
output_file_paths: list[Path] = []
dirname = os.path.dirname(__file__)
applications = _get_applications_from_metadata()
for i in applications:
application = i.get("application")
for output_folder in output_folders:
output_file_path = Path(dirname).joinpath(
"..", output_folder, application, filename
)
if output_file_path.is_file():
output_file_paths.append(output_file_path)
return output_file_paths


def add_no_cache_param(vcs_ref_client):
index_file_paths = _get_output_file_paths("index.html")
for index_file_path in index_file_paths:
print(f"Updating vcs_ref_client: {index_file_path.resolve()}")
index_file_path.write_text(
index_file_path.read_text().replace(
"${boot_params}",
"nocache=" + vcs_ref_client,
)
)

boot_file_paths = _get_output_file_paths("boot.js")
for boot_file_path in boot_file_paths:
print(f"Updating addNoCacheParam URL_PARAMETERS: {boot_file_path.resolve()}")
boot_file_path.write_text(
boot_file_path.read_text().replace(
"addNoCacheParam : false",
"addNoCacheParam : true",
)
)


if __name__ == "__main__":
update_apps_metadata()
vcs_ref_client = os.getenv("VCS_REF_CLIENT", str(random.random()))
add_no_cache_param(vcs_ref_client)
2 changes: 1 addition & 1 deletion services/static-webserver/client/source/boot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</head>
<body>
${preBootJs}
<script type="text/javascript" src="${appPath}boot.js"></script>
<script type="text/javascript" src="${appPath}boot.js?${boot_params}"></script>
</body>
<script>
window.markerConfig = {
Expand Down

0 comments on commit c12285c

Please sign in to comment.