CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/static/production-build.py
Views: 687
1
#!/usr/bin/env python3
2
3
import json, os, shutil
4
5
6
def handle_path(s, path=None):
7
desc = s
8
if path is not None:
9
os.chdir(path)
10
desc += " # in '%s'" % path
11
print(desc)
12
13
14
def cmd(s, path=None):
15
home = os.path.abspath(os.curdir)
16
try:
17
handle_path(s, path)
18
if os.system(s):
19
raise RuntimeError("Error executing '%s'" % s)
20
finally:
21
os.chdir(home)
22
23
24
def app_version():
25
# We also create a versioned app.html file, named "app-[version].html", where
26
# version is taken from package.json. We do this entirely so we easily
27
# run specific versions of the cocalc client code by slightly changing
28
# the URL. Nothing else should depend on this.
29
version = json.loads(open('package.json').read())['version']
30
cmd(f"cp dist/app.html dist/app-{version}.html")
31
32
33
def main():
34
# Build with production BASE_PATH='/'. Note that we also disable disk caching for production builds,
35
# since disk caching **does** randomly break (maybe 10% chance), and despite the speedups, it
36
# is just not worth the risk for production builds!!! If webpack fixes their disk caching bugs,
37
# maybe change this; this may take time, since I couldn't find a reported bug about this now.
38
#
39
# TODO -- this is dumb and we must get rid of hardcoding of the base url. But that is another problem for later...
40
NODE_ENV = os.environ.get('NODE_ENV', 'production')
41
cmd(f"NODE_ENV={NODE_ENV} rspack"
42
)
43
app_version()
44
45
46
if __name__ == "__main__":
47
main()
48
49