Skip to content

Commit a24ea60

Browse files
committed
@pcrespov review
1 parent 830654a commit a24ea60

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

services/static-webserver/client/scripts/post-compile.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import random
4+
from pathlib import Path
45

56
output_folders = [
67
"source-output", # dev output
@@ -40,40 +41,38 @@ def update_apps_metadata():
4041

4142

4243
def _get_output_file_paths(filename):
43-
index_file_paths = []
44+
output_file_paths: list[Path] = []
4445
dirname = os.path.dirname(__file__)
4546
applications = _read_json_file("apps_metadata.json")
4647
for i in applications:
4748
application = i.get("application")
4849
for output_folder in output_folders:
49-
index_file_paths.append(
50-
os.path.join(dirname, "..", output_folder, application, filename)
51-
)
52-
return index_file_paths
50+
result = Path(dirname).joinpath("..", output_folder, application, filename)
51+
if result.is_file():
52+
output_file_paths.append(result.resolve())
53+
return output_file_paths
5354

5455

5556
def add_no_cache_param(vcs_ref_client):
5657
index_file_paths = _get_output_file_paths("index.html")
5758
for index_file_path in index_file_paths:
58-
if not os.path.isfile(index_file_path):
59-
continue
60-
with open(index_file_path) as index_file:
61-
data = index_file.read()
62-
data = data.replace("${boot_params}", "nocache=" + vcs_ref_client)
63-
with open(index_file_path, "w") as file:
64-
print(f"Updating vcs_ref_client: {index_file_path}")
65-
file.write(data)
59+
print(f"Updating vcs_ref_client: {index_file_path}")
60+
index_file_path.write_text(
61+
index_file_path.read_text().replace(
62+
"${boot_params}",
63+
"nocache=" + vcs_ref_client,
64+
)
65+
)
6666

6767
boot_file_paths = _get_output_file_paths("boot.js")
6868
for boot_file_path in boot_file_paths:
69-
if not os.path.isfile(boot_file_path):
70-
continue
71-
with open(boot_file_path) as boot_file:
72-
data = boot_file.read()
73-
data = data.replace("addNoCacheParam : false", "addNoCacheParam : true")
74-
with open(boot_file_path, "w") as file:
75-
print(f"Updating URL_PARAMETERS: {boot_file_path}")
76-
file.write(data)
69+
print(f"Updating addNoCacheParam URL_PARAMETERS: {boot_file_path}")
70+
boot_file_path.write_text(
71+
boot_file_path.read_text().replace(
72+
"addNoCacheParam : false",
73+
"addNoCacheParam : true",
74+
)
75+
)
7776

7877

7978
if __name__ == "__main__":

0 commit comments

Comments
 (0)