-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreplace_path.py
More file actions
57 lines (40 loc) · 1.55 KB
/
replace_path.py
File metadata and controls
57 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Simple utility tool to replace paths in typescript compiled code
"""
import os
import shutil
print("REPLACING PATHS")
ALIAS = "@content/"
REPLACE_WITH = "./"
REPLACE_WITH_END = "../game_content/src/"
DOTS = "../"
FOLDER = "./server/build/server/src"
for root, dirs, files in os.walk(FOLDER):
for file_name in files:
text = ""
with open(root + "\\" + file_name, "r", encoding="utf-8", newline='') as file:
text = file.read()
if text.count(ALIAS) == 0:
continue
dots = DOTS * (root.count("\\") + root.count("/") - 3)
text = text.replace(ALIAS, dots + REPLACE_WITH + REPLACE_WITH_END)
with open(root + "\\" + file_name, "w", encoding="utf-8", newline='') as file:
print(text, file = file)
shutil.copy("./game_content/src/content.js", "./static/content.js")
FOLDER = "./static/"
REPLACE_WITH = "./"
for root, dirs, files in os.walk(FOLDER):
##print(root)
for file_name in files:
if file_name.endswith(".js"):
text = ""
with open(root + "\\" + file_name, "r", encoding="utf-8", newline='') as file:
text = file.read()
if text.count(ALIAS) == 0:
continue
dots = ""
if (root.count("\\") + root.count("/")) > 2:
dots = DOTS * (root.count("\\") + root.count("/") - 1)
text = text.replace(ALIAS, dots + REPLACE_WITH)
with open(root + "\\" + file_name, "w", encoding="utf-8", newline='') as file:
print(text, file = file)