-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.py
107 lines (91 loc) · 2.49 KB
/
build.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
# This file is meant to be used on Unix-like system as most of them have Python 3 preinstalled.
import platform
import os
import shutil
import webbrowser
# Functions
def clear():
if platform.system() == 'Windows':
clearCommand = 'cls'
else:
clearCommand = 'clear'
os.system(clearCommand)
def boolQuestion(question):
while True:
answer = input(f"{question} (y/n)")
if answer == "y":
return True
elif answer == "n":
return False
else:
print("Err: Invalid Answer")
def startswithnum(num):
try:
num = int(num)
return True
except ValueError:
return False
def prettyListPrint(grossList, selected=None):
i = 0
for item in grossList:
i += 1
if selected is not None:
if i == selected:
print(f"\t{i}: {item} <")
else:
print(f"\t{i}: {item}")
else:
print(f"\t{i}: {item}")
def main():
print("Welcome to the Coffee Engine builder!")
# Friendly OS names
match platform.system():
case "Windows":
displayOS = "Windows"
case "Darwin":
displayOS = "macOS"
case "Linux":
displayOS = "Linux"
case _:
displayOS = "Unknown"
print(f"Detected OS: {displayOS}\n")
if shutil.which("node") is None:
print("Err: You don't have Node.js installed, please download it from https://nodejs.org/en")
exit(1)
selected = 1
while True:
clear()
print("Welcome to the Coffee Engine builder!")
print(f"Detected OS: {displayOS}\n")
print("Build options")
prettyListPrint(buildOptions, selected)
cmd = input(":")
if startswithnum(cmd):
selected = int(cmd)
elif cmd == "q": # Exit
clear()
exit(0)
elif cmd == "": # Confirm
execute(selected)
def execute(option):
# Check OS Python command
if platform.system() == "Windows":
pyCommand = "py"
else:
pyCommand = "python3"
# Actual execution
if option == 1:
webbrowser.open("http://0.0.0.0:8000/src/")
os.system(f"{pyCommand} -m http.server")
if option == 2:
os.system("npm run start")
if option == 3:
os.system("npm i electron-forge")
os.system("npm run package")
exit(0)
buildOptions = [
"Web Server",
"Dev Window",
"Electron (Host OS)"
]
main()