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/cdn/setup.py
Views: 687
1
#!/usr/bin/env python3
2
3
import os
4
from os.path import join, abspath, dirname, islink, exists
5
import json
6
from shutil import copytree
7
8
curdir = dirname(abspath(__file__))
9
os.chdir(join(curdir, 'dist'))
10
11
extra_path = {
12
'katex': 'dist/',
13
}
14
15
deps = json.load(open(join('..', 'package-lock.json')))["dependencies"]
16
targets = list(
17
json.load(open(join('..', 'package.json')))["devDependencies"].keys())
18
BLACKLIST = ["typescript"]
19
20
versions = {}
21
for path, data in deps.items():
22
if any(path.startswith(b) for b in BLACKLIST):
23
continue
24
if '/' in path:
25
name = path.split('/')[-1]
26
else:
27
name = path
28
if name not in targets:
29
continue
30
extra = extra_path.get(name, '')
31
# links must be relative to the current directory (we want to be able to move the directory around)
32
src = join("..", "node_modules", path, extra)
33
if not exists(src):
34
raise Exception(
35
f"target '{src}' does not exist -- did you forget to run 'npm ci' in '{curdir}'?"
36
)
37
version = data['version']
38
copytree(src, name)
39
dst = f"{name}-{version}"
40
print(f"symlink with version '{dst}' -> '{src}'")
41
os.symlink(name, dst)
42
versions[name] = version
43
44
# finally, write the version info such that it can be loaded
45
with open('index.js', 'w') as out:
46
out.write(f"""
47
"use strict";
48
exports.__esModule = true;
49
exports.path = exports.versions = void 0;
50
exports.versions = {json.dumps(versions)};
51
exports.path = __dirname;
52
""")
53
54