-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.py
89 lines (70 loc) · 3.25 KB
/
t.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
import os
import subprocess
import sys
cur_directory = os.path.dirname(os.path.abspath(__file__))
def run_example(path, extra_cmd=None):
command = f"cd examples/{path} && yarn run dev"
if extra_cmd:
command += f" && {extra_cmd}"
print(command)
subprocess.run(["yarn", "concurrently", "-n", path, "-c", "#fb8500", command])
def main():
if len(sys.argv) < 2:
print("Usage: ./t build|run [command]")
return
# print(sys.argv)
try:
if sys.argv[1] == "build":
command1 = ["yarn", "run", "build"]
subprocess.run(command1, env=os.environ.copy())
example_dir = os.path.join("examples", sys.argv[2])
os.chdir(example_dir)
command2 = ["yarn", "run", "build"]
subprocess.run(command2, env=os.environ.copy())
if sys.argv[1] == "run":
if sys.argv[2] == "dev":
subcommands = ["./t run anvil", f"./t run framework {' '.join(sys.argv[3:])} && ./t run {sys.argv[3]} {' '.join(sys.argv[4:])}"]
command = ["yarn", "concurrently", "-n", "anvil,contracts", "-c", "blue,green"] + subcommands
# Copy the current environment and modify it
env = os.environ.copy()
env["NODE_ENV"] = "development"
subprocess.run(command, env=env)
if sys.argv[2] == "prod":
subcommands = [f"./t run framework {' '.join(sys.argv[3:])} && ./t run {sys.argv[3]} {' '.join(sys.argv[4:])}"]
command = ["yarn", "concurrently", "-n", "contracts", "-c", "green"] + subcommands
env = os.environ.copy()
env["NODE_ENV"] = "production"
subprocess.run(command, env=env)
elif sys.argv[2] == "anvil":
os.chdir("scripts")
subprocess.run(["yarn", "run", "anvil"])
elif sys.argv[2] == "framework":
if "--skip-build" in sys.argv:
subprocess.run(["yarn", "run", "registry"])
else:
subprocess.run(["yarn", "run", "dev"])
elif sys.argv[2] == "basic-world":
run_example("basic-world")
elif sys.argv[2] == "everlon":
extra_cmd = []
if "--with-extensions" in sys.argv:
extra_cmd.append("yarn run deploy:extensions")
if "--with-pretty" in sys.argv:
extra_cmd.append("yarn run deploy:pretty")
if "--with-derived" in sys.argv:
extra_cmd.append("yarn run deploy:derived")
if "--snapshot" in sys.argv:
extra_cmd.append(f"sh {cur_directory}/scripts/rollback/createSnapshot.sh")
# Join the commands with ' && '
command_str = " && ".join(extra_cmd)
run_example("everlon", command_str)
elif sys.argv[2] == "snapshot":
subprocess.run([f"sh {cur_directory}/scripts/rollback/createSnapshot.sh"])
print("created snapshot")
else:
print("Invalid command: " + sys.argv[2])
except KeyboardInterrupt:
print("\nInterrupted by user. Exiting...")
sys.exit(1)
if __name__ == "__main__":
main()