Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions services/static-webserver/client/scripts/post-compile.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,82 @@
import os
import json

import os
import random

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 _read_json_file(filename):
dirname = os.path.dirname(__file__)
meta_filename = os.path.join(dirname, filename)
with open(meta_filename, "r") as file:
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 = _read_json_file("apps_metadata.json")
for i in applications:
application = i.get("application")
replacements = i.get("replacements")
for output_folder in output_folders:
filename = os.path.join(dirname, '..', output_folder, application, "index.html")
filename = os.path.join(
dirname, "..", output_folder, application, "index.html"
)
if not os.path.isfile(filename):
continue
with open(filename, "r") as file:
with open(filename) as file:
data = file.read()
replacements = i.get("replacements")
for key in replacements:
replace_text = replacements[key]
data = data.replace("${"+key+"}", replace_text)
with open(filename, "w") as file:
data = data.replace("${" + key + "}", replace_text)
with open(filename, "w") as file:
print(f"Updating app metadata: {filename}")
file.write(data)


def _get_output_file_paths(filename):
index_file_paths = []
dirname = os.path.dirname(__file__)
applications = _read_json_file("apps_metadata.json")
for i in applications:
application = i.get("application")
for output_folder in output_folders:
index_file_paths.append(
os.path.join(dirname, "..", output_folder, application, filename)
)
return index_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:
if not os.path.isfile(index_file_path):
continue
with open(index_file_path) as index_file:
data = index_file.read()
data = data.replace("${boot_params}", "nocache=" + vcs_ref_client)
with open(index_file_path, "w") as file:
print(f"Updating vcs_ref_client: {index_file_path}")
file.write(data)

boot_file_paths = _get_output_file_paths("boot.js")
for boot_file_path in boot_file_paths:
if not os.path.isfile(boot_file_path):
continue
with open(boot_file_path) as boot_file:
data = boot_file.read()
data = data.replace("addNoCacheParam : false", "addNoCacheParam : true")
with open(boot_file_path, "w") as file:
print(f"Updating URL_PARAMETERS: {boot_file_path}")
file.write(data)


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
Loading