This repository has been archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
74 lines (59 loc) · 1.94 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
from os import mkdir, walk
from os.path import join, relpath
from subprocess import check_call
class GUIFilter:
def __init__(self, proj_file):
self.proj_file = proj_file
@classmethod
def include(cls, name):
ext = name.split(".")[-1]
return ext in ["html", "js", "gif", "css", "ttf", "ico", "py", "txt", "png", "LICENSE"]
def exclude(self, name):
if name.split(".")[-1] in ["map", "pyc"]:
return True
return name in [
"Procfile",
"requirements.txt",
"asset-manifest.json",
"runtime.txt",
"manifest.json",
"robots.txt",
"service-worker.js",
".git",
self.proj_file,
]
@staticmethod
def require_same(name):
return name in ["dice.py", "ucb.py", "utils.py"]
BUILD_OUTPUT_LOC = "deploy"
def read(path):
with open(path, "rb") as f:
return f.read()
def main(proj_file, location):
filt = GUIFilter(proj_file)
check_call(["yarn", "build"])
for dirpath, _, filenames in walk(BUILD_OUTPUT_LOC):
outdir = join(location, relpath(dirpath, BUILD_OUTPUT_LOC))
try:
mkdir(outdir)
except FileExistsError:
pass
for name in filenames:
inp = join(dirpath, name)
out = join(outdir, name)
if filt.exclude(name):
pass
elif filt.include(name):
check_call(["cp", inp, out])
elif filt.require_same(name):
with open(inp) as f:
inp_c = f.read()
with open(out) as f:
out_c = f.read()
if inp_c != out_c:
raise RuntimeError("{} is different from {}".format(inp, out))
else:
raise RuntimeError("unrecognized file: {}".format(inp))
if __name__ == "__main__":
from sys import argv
main(*argv[1:])