-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
155 lines (125 loc) · 4.68 KB
/
build.py
File metadata and controls
155 lines (125 loc) · 4.68 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import subprocess
import sys
from pathlib import Path
import shutil
import json
def get_user_input(prompt, default=None):
if default:
user_input = input(f"{prompt} [{default}]: ").strip()
return user_input if user_input else default
return input(f"{prompt}: ").strip()
def yes_no_prompt(prompt, default=True):
default_str = "Y/n" if default else "y/N"
response = input(f"{prompt} [{default_str}]: ").strip()
if not response:
return default
return response in ['y', 'yes']
def main():
print("=" * 60)
print(" DRAGONSREALM BUILD TOOL")
print(" Version 1.0")
print("=" * 60)
print()
#Get the path(s) to the user's web folders
print("CONFIGURATION")
print("-" * 60)
current_folder = get_user_input(
"Enter the CURRENT folder name (this includes files that you want to deploy as a new update)",
"Current"
)
new_folder = get_user_input(
"Enter the versioned folder name (where versioned files will go)",
"Verioned"
)
use_previous = yes_no_prompt(
"Do you have a PREVIOUS deployment to compare against? (e.g., files that have already been hosted live)",
False
)
previous_folder = None
if use_previous:
previous_folder = get_user_input(
"Enter the PREVIOUS folder name (for version comparison)",
"Previous"
)
#Ensure folders exist
current_path = Path(current_folder)
if not current_path.exists():
print(f"Folder '{current_folder}' does not exist!")
sys.exit(1)
if previous_folder:
previous_path = Path(previous_folder)
if not previous_path.exists():
print(f"[Warning] Folder '{previous_folder}' does not exist!")
print(f"Continuing without version comparison...")
previous_folder = None
# Create new folder if it doesn't exist
new_path = Path(new_folder)
if new_path.exists():
if yes_no_prompt(f"[Warning] '{new_folder}' already exists. Replace it?", False):
shutil.rmtree(new_path)
print(f"Deleted old '{new_folder}' folder")
else:
print("Using existing folder (files may be overwritten)")
#Run the versioning script
print("VERSIONING FILES")
print("-" * 60)
try:
#Change the version_manager.py's Configurations
with open("version_config.json", "w", encoding='utf-8') as config_file:
config_data = {
"source_dir": f"{current_folder}/public",
"output_dir": f"{new_folder}/public",
"previous_version_dir": f"{previous_folder}/public" if previous_folder else None
}
json.dump(config_data, config_file, indent=4)
# Run version_manager.py
result = subprocess.run([sys.executable, "version_manager.py"],
capture_output=False, text=True)
if result.returncode != 0:
print("Versioning failed!")
sys.exit(1)
print("Versioning complete!")
except Exception as e:
print(f"Error during versioning: {e}")
sys.exit(1)
#After running the versioning, now run the minification script
print("MINIFYING FILES")
print("-" * 60)
if yes_no_prompt("Remove all console.log lines from JavaScript?", True) is True:
remove_console_logs = True
else:
remove_console_logs = False
try:
with open("minify_config.json", "w", encoding='utf-8') as config_file:
config_data = {
"source_dir": f"{new_folder}/public",
"output_dir": "dist/public",
"remove_console_logs": remove_console_logs,
"verbose": "False"
}
json.dump(config_data, config_file, indent=4)
# Run minification
result = subprocess.run([sys.executable, "minification.py"],
capture_output=False, text=True)
if result.returncode != 0:
print("Minification failed!")
sys.exit(1)
print("Minification complete!")
except Exception as e:
print(f"Error during minification: {e}")
sys.exit(1)
print()
# Step 5: Summary
print("=" * 60)
print("BUILD COMPLETE!")
print("=" * 60)
print(f"The processed files are in: dist2/")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Build Cancelled")
sys.exit(1)
except Exception as e:
print(f"Unexpected error: {e}")
sys.exit(1)