-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·114 lines (75 loc) · 2.72 KB
/
run
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
#!/usr/bin/env python3
"""Build/dev runner for our game."""
import argparse
import datetime
import os
import shutil
import subprocess
import sys
IMAGE = "kadigan"
def sh(*cmd, cwd=None):
if subprocess.call(cmd, cwd=cwd):
sys.exit(1)
def docker(*cmd, ports=(), image=IMAGE):
cwd = os.getcwd()
sh("docker", "run", "--rm", "--interactive", "--tty",
"--volume", f"{cwd}:{cwd}", "--workdir", cwd,
"--user", f"{os.getuid()}:{os.getgid()}",
*(arg for port in ports for arg in ["--publish", f"{port}:{port}"]),
image, *cmd)
def build():
sh("docker", "build", "--rm", "-t", IMAGE, ".")
def run(cmd):
docker(*cmd)
def npm(cmd):
docker("npm", *cmd)
def tsc(watch):
args = ["--watch"] if watch else []
docker("npm", "run", "tsc", "--", *args)
def test(watch):
args = ["--watch"] if watch else []
docker("npm", "run", "test", "--", *args)
def lint():
docker("npm", "run", "lint")
def check():
docker("npm", "run", "check")
def start():
docker("npm", "run", "start", ports=(1234, 12345))
def release():
os.makedirs("release", exist_ok=True)
filename = os.path.join("release", f"Kadigan_{datetime.datetime.now().date().isoformat()}.zip")
if os.path.exists(filename):
print(f"Error! release file {filename} already exists", file=sys.stderr)
return
shutil.rmtree("dist")
docker("npm", "run", "build")
sh("zip", f"../{filename}", "-r", ".", cwd="dist")
def notebook():
docker(image="jupyter/scipy-notebook:42f4c82a07ff", ports=(8888,))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.set_defaults(action=lambda: parser.print_help())
subparsers = parser.add_subparsers()
subparsers.add_parser("build").set_defaults(action=build)
p = subparsers.add_parser("run")
p.add_argument("cmd", nargs="*")
p.set_defaults(action=run)
p = subparsers.add_parser("npm")
p.add_argument("cmd", nargs="*")
p.set_defaults(action=npm)
p = subparsers.add_parser("tsc")
p.add_argument("-w", "--watch", action="store_true", help="Watch input files")
p.set_defaults(action=tsc)
p = subparsers.add_parser("test")
p.add_argument("-w", "--watch", action="store_true", help="Watch input files")
p.set_defaults(action=test)
subparsers.add_parser("lint").set_defaults(action=lint)
subparsers.add_parser("check").set_defaults(action=check)
subparsers.add_parser("start").set_defaults(action=start)
subparsers.add_parser("release").set_defaults(action=release)
subparsers.add_parser("notebook").set_defaults(action=notebook)
args = vars(parser.parse_args())
action = args.pop("action")
action(**args)
if __name__ == "__main__":
main()