1
1
const fs = require ( "fs" ) ;
2
2
const path = require ( "path" ) ;
3
3
4
+ const isWin = process . platform === "win32" ;
5
+ const LINK_TYPE = isWin ? "junction" : "dir" ;
6
+
7
+ function ensureDir ( p ) {
8
+ fs . mkdirSync ( p , { recursive : true } ) ;
9
+ }
10
+
4
11
function ensureSymlink ( sourcePath , targetPath ) {
5
12
const source = path . resolve ( sourcePath ) ;
6
13
const target = path . resolve ( targetPath ) ;
7
14
15
+ ensureDir ( path . dirname ( target ) ) ;
16
+
17
+ if ( ! fs . existsSync ( source ) ) {
18
+ console . warn ( `Skipping symlink; source missing: ${ source } ` ) ;
19
+ return false ;
20
+ }
21
+
8
22
try {
9
23
const stat = fs . lstatSync ( target ) ;
10
24
if ( ! stat . isSymbolicLink ( ) ) {
11
25
console . log ( `Removing non-symlink at: ${ target } ` ) ;
12
26
fs . rmSync ( target , { recursive : true , force : true } ) ;
13
27
} else {
14
- const exists = fs . readlinkSync ( target ) ;
15
- if ( path . resolve ( exists ) === source ) {
16
- console . log ( `Symlink exists at: ${ target } ` ) ;
17
- return ;
18
- }
19
- console . log ( `Replacing symlink at: ${ target } ` ) ;
20
- fs . unlinkSync ( target ) ;
28
+ const exists = fs . readlinkSync ( target ) ;
29
+ if ( path . resolve ( exists ) === source ) {
30
+ console . log ( `Symlink exists at: ${ target } ` ) ;
31
+ return ;
32
+ }
33
+ console . log ( `Replacing symlink at: ${ target } ` ) ;
34
+ fs . unlinkSync ( target ) ;
21
35
}
22
36
} catch ( e ) {
23
37
if ( e . code !== "ENOENT" ) {
@@ -26,11 +40,7 @@ function ensureSymlink(sourcePath, targetPath) {
26
40
}
27
41
28
42
try {
29
- fs . symlinkSync (
30
- path . resolve ( source ) ,
31
- path . resolve ( target ) ,
32
- "junction"
33
- ) ;
43
+ fs . symlinkSync ( source , target , LINK_TYPE ) ;
34
44
console . log ( `Symlink created: ${ sourcePath } -> ${ targetPath } ` ) ;
35
45
} catch ( e ) {
36
46
if ( e . code !== "EEXIST" ) {
@@ -39,88 +49,31 @@ function ensureSymlink(sourcePath, targetPath) {
39
49
}
40
50
}
41
51
42
- // Symlink other static assets no longer in bower_components
43
- ensureSymlink (
44
- "node_modules/marked" ,
45
- "nbclassic/static/components/marked"
46
- ) ;
47
- ensureSymlink (
48
- "node_modules/font-awesome" ,
49
- "nbclassic/static/components/font-awesome"
50
- ) ;
51
- ensureSymlink (
52
- "node_modules/backbone" ,
53
- "nbclassic/static/components/backbone"
54
- ) ;
55
- ensureSymlink (
56
- "node_modules/bootstrap" ,
57
- "nbclassic/static/components/bootstrap"
58
- ) ;
59
- ensureSymlink (
60
- "node_modules/bootstrap-tour" ,
61
- "nbclassic/static/components/bootstrap-tour"
62
- ) ;
63
- ensureSymlink (
64
- "node_modules/jed" ,
65
- "nbclassic/static/components/jed"
66
- ) ;
67
- ensureSymlink (
68
- "node_modules/moment" ,
69
- "nbclassic/static/components/moment"
70
- ) ;
71
- ensureSymlink (
72
- "node_modules/text-encoding" ,
73
- "nbclassic/static/components/text-encoding"
74
- ) ;
75
- ensureSymlink (
76
- "node_modules/underscore" ,
77
- "nbclassic/static/components/underscore"
78
- ) ;
79
- ensureSymlink (
80
- "node_modules/jquery" ,
81
- "nbclassic/static/components/jquery"
82
- ) ;
83
- ensureSymlink (
84
- "node_modules/jquery-ui" ,
85
- "nbclassic/static/components/jquery-ui"
86
- ) ;
87
- ensureSymlink (
88
- "node_modules/jquery-typeahead" ,
89
- "nbclassic/static/components/jquery-typeahead"
90
- ) ;
91
- ensureSymlink (
92
- "node_modules/mathjax" ,
93
- "nbclassic/static/components/MathJax"
94
- ) ;
95
- ensureSymlink (
96
- "node_modules/codemirror" ,
97
- "nbclassic/static/components/codemirror"
98
- ) ;
99
- ensureSymlink (
100
- "node_modules/react" ,
101
- "nbclassic/static/components/react"
102
- ) ;
103
- ensureSymlink (
104
- "node_modules/react-dom" ,
105
- "nbclassic/static/components/react-dom"
106
- ) ;
107
- ensureSymlink (
108
- "node_modules/es6-promise" ,
109
- "nbclassic/static/components/es6-promise"
110
- ) ;
111
- ensureSymlink (
112
- "node_modules/requirejs" ,
113
- "nbclassic/static/components/requirejs"
114
- ) ;
115
- ensureSymlink (
116
- "node_modules/requirejs-plugins" ,
117
- "nbclassic/static/components/requirejs-plugins"
118
- ) ;
119
- ensureSymlink (
120
- "node_modules/requirejs-text" ,
121
- "nbclassic/static/components/requirejs-text"
122
- ) ;
123
- ensureSymlink (
124
- "node_modules/google-caja-sanitizer" ,
125
- "nbclassic/static/components/google-caja-sanitizer"
126
- ) ;
52
+ ensureDir ( "nbclassic/static/components" ) ;
53
+
54
+ [
55
+ "marked" ,
56
+ "font-awesome" ,
57
+ "backbone" ,
58
+ "bootstrap" ,
59
+ "bootstrap-tour" ,
60
+ "jed" ,
61
+ "moment" ,
62
+ "text-encoding" ,
63
+ "underscore" ,
64
+ "jquery" ,
65
+ "jquery-ui" ,
66
+ "jquery-typeahead" ,
67
+ "codemirror" ,
68
+ "react" ,
69
+ "react-dom" ,
70
+ "es6-promise" ,
71
+ "requirejs" ,
72
+ "requirejs-plugins" ,
73
+ "requirejs-text" ,
74
+ "google-caja-sanitizer" ,
75
+ "mathjax" ,
76
+ ] . forEach ( ( pkg ) => {
77
+ const dst = pkg === "mathjax" ? "MathJax" : pkg ;
78
+ ensureSymlink ( `node_modules/${ pkg } ` , `nbclassic/static/components/${ dst } ` ) ;
79
+ } ) ;
0 commit comments