11const fs = require ( "fs" ) ;
22const path = require ( "path" ) ;
33
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+
411function ensureSymlink ( sourcePath , targetPath ) {
512 const source = path . resolve ( sourcePath ) ;
613 const target = path . resolve ( targetPath ) ;
714
15+ ensureDir ( path . dirname ( target ) ) ;
16+
17+ if ( ! fs . existsSync ( source ) ) {
18+ console . warn ( `Skipping symlink; source missing: ${ source } ` ) ;
19+ return false ;
20+ }
21+
822 try {
923 const stat = fs . lstatSync ( target ) ;
1024 if ( ! stat . isSymbolicLink ( ) ) {
1125 console . log ( `Removing non-symlink at: ${ target } ` ) ;
1226 fs . rmSync ( target , { recursive : true , force : true } ) ;
1327 } 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 ) ;
2135 }
2236 } catch ( e ) {
2337 if ( e . code !== "ENOENT" ) {
@@ -26,11 +40,7 @@ function ensureSymlink(sourcePath, targetPath) {
2640 }
2741
2842 try {
29- fs . symlinkSync (
30- path . resolve ( source ) ,
31- path . resolve ( target ) ,
32- "junction"
33- ) ;
43+ fs . symlinkSync ( source , target , LINK_TYPE ) ;
3444 console . log ( `Symlink created: ${ sourcePath } -> ${ targetPath } ` ) ;
3545 } catch ( e ) {
3646 if ( e . code !== "EEXIST" ) {
@@ -39,87 +49,31 @@ function ensureSymlink(sourcePath, targetPath) {
3949 }
4050}
4151
42- // Symlink bower_components
43- ensureSymlink ( "node_modules/@bower_components" , "nbclassic/static/components" ) ;
52+ ensureDir ( "nbclassic/static/components" ) ;
4453
45- // Symlink other static assets no longer in bower_components
46- ensureSymlink (
47- "node_modules/marked" ,
48- "nbclassic/static/components/marked"
49- ) ;
50- ensureSymlink (
51- "node_modules/font-awesome" ,
52- "nbclassic/static/components/font-awesome"
53- ) ;
54- ensureSymlink (
55- "node_modules/backbone" ,
56- "nbclassic/static/components/backbone"
57- ) ;
58- ensureSymlink (
59- "node_modules/bootstrap" ,
60- "nbclassic/static/components/bootstrap"
61- ) ;
62- ensureSymlink (
63- "node_modules/bootstrap-tour" ,
64- "nbclassic/static/components/bootstrap-tour"
65- ) ;
66- ensureSymlink (
67- "node_modules/jed" ,
68- "nbclassic/static/components/jed"
69- ) ;
70- ensureSymlink (
71- "node_modules/moment" ,
72- "nbclassic/static/components/moment"
73- ) ;
74- ensureSymlink (
75- "node_modules/text-encoding" ,
76- "nbclassic/static/components/text-encoding"
77- ) ;
78- ensureSymlink (
79- "node_modules/underscore" ,
80- "nbclassic/static/components/underscore"
81- ) ;
82- ensureSymlink (
83- "node_modules/jquery" ,
84- "nbclassic/static/components/jquery"
85- ) ;
86- ensureSymlink (
87- "node_modules/jquery-ui" ,
88- "nbclassic/static/components/jquery-ui"
89- ) ;
90- ensureSymlink (
91- "node_modules/jquery-typeahead" ,
92- "nbclassic/static/components/jquery-typeahead"
93- ) ;
94- ensureSymlink (
95- "node_modules/mathjax" ,
96- "nbclassic/static/components/MathJax"
97- ) ;
98- ensureSymlink (
99- "node_modules/codemirror" ,
100- "nbclassic/static/components/codemirror"
101- ) ;
102- ensureSymlink (
103- "node_modules/react" ,
104- "nbclassic/static/components/react"
105- ) ;
106- ensureSymlink (
107- "node_modules/react-dom" ,
108- "nbclassic/static/components/react-dom"
109- ) ;
110- ensureSymlink (
111- "node_modules/es6-promise" ,
112- "nbclassic/static/components/es6-promise"
113- ) ;
114- ensureSymlink (
115- "node_modules/requirejs" ,
116- "nbclassic/static/components/requirejs"
117- ) ;
118- ensureSymlink (
119- "node_modules/requirejs-plugins" ,
120- "nbclassic/static/components/requirejs-plugins"
121- ) ;
122- ensureSymlink (
123- "node_modules/requirejs-text" ,
124- "nbclassic/static/components/requirejs-text"
125- ) ;
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