-
Notifications
You must be signed in to change notification settings - Fork 0
/
confab-builder.py
114 lines (82 loc) · 4.42 KB
/
confab-builder.py
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
import os
import argparse
from pathlib import Path
import shutil
confab_dir = Path("./Confab")
confab_UI_dir = Path("./ConfabUI")
confab_emails_dir = Path("./email_designs")
confab_build_dir = Path("./App")
def is_tool(name):
"""Check whether `name` is on PATH and marked as executable."""
from shutil import which
return which(name) is not None
def build_ui():
from ConfabUI.build import build as buildUI
buildUI()
def ignore_files(dir, files):
ignore_list = []
if(os.path.exists(confab_build_dir / "appsettings.json")): ignore_list.append('appsettings.json')
return [file for file in files if file in ignore_list]
def build_backend(clean = False, platform = ""):
abspath = os.path.abspath(__file__)
current_dir = os.path.dirname(abspath)
os.chdir(str(current_dir))
if(not os.path.exists(confab_dir / "App_Data")): os.mkdir(confab_dir / "App_Data")
if(not os.path.exists(confab_dir / "App_Data/email_templates")): os.mkdir(confab_dir / "App_Data/email_templates")
from email_designs.compile import compile as compile_emails
compile_emails()
if(not is_tool("dotnet")):
print("dotnet devtools is required to build Confab backend, but it doesn't seem to be installed. Install dotnet and try again")
print("See https://docs.confabcomments.com/development/#prerequisites")
exit()
if(clean):
os.system("dotnet clean")
print("Building Confab backend...")
abspath = os.path.abspath(__file__)
current_dir = os.path.dirname(abspath)
os.chdir(str(current_dir / confab_dir))
if platform == "" or platform == None:
platform_arg = ""
else:
platform_arg = "--runtime " + platform
bundle_runtime = "--self-contained true" if args.bundle_runtime else "--self-contained false"
os.system(f"dotnet publish --configuration Release --output build {platform_arg} {bundle_runtime}")
os.chdir(str(current_dir))
shutil.copytree(Path("./Confab/build"), confab_build_dir, dirs_exist_ok = True, ignore=ignore_files)
shutil.copytree(Path("./Confab/scripts"), confab_build_dir, dirs_exist_ok = True)
if(os.path.exists(Path("./Confab/build"))): shutil.rmtree(Path("./Confab/build"))
print("\n✅✅✅ Building Confab backend complete! ✅✅✅")
print("Output files are in ./App/\n")
def transfer_ui_to_backend():
abspath = os.path.abspath(__file__)
current_dir = os.path.dirname(abspath)
os.chdir(str(current_dir))
if(not os.path.exists(confab_dir / "wwwroot")): os.mkdir(confab_dir / "wwwroot")
confab_UI_build_dir = confab_UI_dir / "dist"
confab_backend_UI_files_dir = confab_dir / "wwwroot"
shutil.copytree(confab_UI_build_dir, confab_backend_UI_files_dir, dirs_exist_ok = True)
if __name__ == "__main__":
parser = argparse.ArgumentParser("confab_builder")
parser.add_argument("-m", "--mode", choices=["ui", "backend", "full"], default="full", help="Choose whether to build UI, backend, or both")
parser.add_argument("-c", "--clean", action="store_true", help="Clean build")
parser.add_argument("-p", "--platform", help="Compile .NET backend for specific platform (leave empty for current platform).")
parser.add_argument("-b", "--bundle-runtime", action="store_true", help="Bundle .NET runtime (will run without requiring .NET runtime to be installed, but will increase build size)")
args = parser.parse_args()
abspath = os.path.abspath(__file__)
current_dir = os.path.dirname(abspath)
os.chdir(str(current_dir))
if(args.clean):
print("Cleaning build files")
if(os.path.exists(confab_UI_dir / "node_modules")): shutil.rmtree(confab_UI_dir / "node_modules")
if(os.path.exists(confab_UI_dir / "dist")): shutil.rmtree(confab_UI_dir / "dist")
if(os.path.exists(confab_dir / "App_Data")): shutil.rmtree(confab_dir / "App_Data")
if(os.path.exists(confab_dir / "bin")): shutil.rmtree(confab_dir / "bin")
if(os.path.exists(confab_dir / "build")): shutil.rmtree(confab_dir / "build")
if(os.path.exists(confab_dir / "wwwroot")): shutil.rmtree(confab_dir / "wwwroot")
if(os.path.exists(confab_emails_dir / "node_modules")): shutil.rmtree(confab_emails_dir / "node_modules")
if(args.mode == "full" or args.mode == "ui"):
build_ui()
if(args.mode == "full"):
transfer_ui_to_backend()
if(args.mode == "full" or args.mode == "backend"):
build_backend(args.clean, args.platform)