-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathpostinstall.js
More file actions
79 lines (70 loc) · 1.83 KB
/
postinstall.js
File metadata and controls
79 lines (70 loc) · 1.83 KB
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
const fs = require("fs");
const path = require("path");
const isWin = process.platform === "win32";
const LINK_TYPE = isWin ? "junction" : "dir";
function ensureDir(p) {
fs.mkdirSync(p, { recursive: true });
}
function ensureSymlink(sourcePath, targetPath) {
const source = path.resolve(sourcePath);
const target = path.resolve(targetPath);
ensureDir(path.dirname(target));
if (!fs.existsSync(source)) {
console.warn(`Skipping symlink; source missing: ${source}`);
return false;
}
try {
const stat = fs.lstatSync(target);
if (!stat.isSymbolicLink()) {
console.log(`Removing non-symlink at: ${target}`);
fs.rmSync(target, { recursive: true, force: true });
} else {
const exists = fs.readlinkSync(target);
if (path.resolve(exists) === source) {
console.log(`Symlink exists at: ${target}`);
return;
}
console.log(`Replacing symlink at: ${target}`);
fs.unlinkSync(target);
}
} catch (e) {
if (e.code !== "ENOENT") {
console.error(`Error checking symlink: ${e.message}`);
}
}
try {
fs.symlinkSync(source, target, LINK_TYPE);
console.log(`Symlink created: ${sourcePath} -> ${targetPath}`);
} catch (e) {
if (e.code !== "EEXIST") {
console.error(`Error creating symlink: ${e.message}`);
}
}
}
ensureDir("nbclassic/static/components");
[
"marked",
"font-awesome",
"backbone",
"bootstrap",
"bootstrap-tour",
"jed",
"moment",
"text-encoding",
"underscore",
"jquery",
"jquery-ui",
"jquery-typeahead",
"codemirror",
"react",
"react-dom",
"es6-promise",
"requirejs",
"requirejs-plugins",
"requirejs-text",
"google-caja-sanitizer",
"mathjax",
].forEach((pkg) => {
const dst = pkg === "mathjax" ? "MathJax" : pkg;
ensureSymlink(`node_modules/${pkg}`, `nbclassic/static/components/${dst}`);
});