@@ -32,83 +32,89 @@ async function build(opts) {
32
32
nodeResolve ( ) ,
33
33
replace ( {
34
34
__VERSION__ : version ,
35
- } )
35
+ } ) ,
36
36
] ,
37
37
onwarn ( message ) {
38
38
if ( message . code === 'UNRESOLVED_IMPORT' ) {
39
39
throw new Error (
40
40
`Could not resolve module ` +
41
- message . source +
42
- `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` +
43
- `Module ${ message . source } is imported in ${ message . importer } `
44
- )
41
+ message . source +
42
+ `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` +
43
+ `Module ${ message . source } is imported in ${ message . importer } `
44
+ ) ;
45
45
}
46
- }
46
+ } ,
47
47
} )
48
48
. then ( bundle => {
49
- const dest = 'lib/' + ( opts . output || opts . input )
49
+ const dest = 'lib/' + ( opts . output || opts . input ) ;
50
50
51
- console . log ( dest )
51
+ console . log ( dest ) ;
52
52
return bundle . write ( {
53
53
format : 'iife' ,
54
- output : opts . globalName ? { name : opts . globalName } : { } ,
54
+ output : opts . globalName ? { name : opts . globalName } : { } ,
55
55
file : dest ,
56
- strict : false
57
- } )
58
- } )
56
+ strict : false ,
57
+ } ) ;
58
+ } ) ;
59
59
}
60
60
61
61
async function buildCore ( ) {
62
- const promises = [ ]
62
+ const promises = [ ] ;
63
63
64
- promises . push ( build ( {
65
- input : 'src/core/index.js' ,
66
- output : 'docsify.js' ,
67
- } ) )
64
+ promises . push (
65
+ build ( {
66
+ input : 'src/core/index.js' ,
67
+ output : 'docsify.js' ,
68
+ } )
69
+ ) ;
68
70
69
71
if ( isProd ) {
70
- promises . push ( build ( {
71
- input : 'src/core/index.js' ,
72
- output : 'docsify.min.js' ,
73
- plugins : [ uglify ( ) ]
74
- } ) )
72
+ promises . push (
73
+ build ( {
74
+ input : 'src/core/index.js' ,
75
+ output : 'docsify.min.js' ,
76
+ plugins : [ uglify ( ) ] ,
77
+ } )
78
+ ) ;
75
79
}
76
80
77
- await Promise . all ( promises )
81
+ await Promise . all ( promises ) ;
78
82
}
79
83
80
84
async function buildAllPlugin ( ) {
81
85
const plugins = [
82
- { name : 'search' , input : 'search/index.js' } ,
83
- { name : 'ga' , input : 'ga.js' } ,
84
- { name : 'gtag' , input : 'gtag.js' } ,
85
- { name : 'matomo' , input : 'matomo.js' } ,
86
- { name : 'emoji' , input : 'emoji.js' } ,
87
- { name : 'external-script' , input : 'external-script.js' } ,
88
- { name : 'front-matter' , input : 'front-matter/index.js' } ,
89
- { name : 'zoom-image' , input : 'zoom-image.js' } ,
90
- { name : 'disqus' , input : 'disqus.js' } ,
91
- { name : 'gitalk' , input : 'gitalk.js' }
92
- ]
86
+ { name : 'search' , input : 'search/index.js' } ,
87
+ { name : 'ga' , input : 'ga.js' } ,
88
+ { name : 'gtag' , input : 'gtag.js' } ,
89
+ { name : 'matomo' , input : 'matomo.js' } ,
90
+ { name : 'emoji' , input : 'emoji.js' } ,
91
+ { name : 'external-script' , input : 'external-script.js' } ,
92
+ { name : 'front-matter' , input : 'front-matter/index.js' } ,
93
+ { name : 'zoom-image' , input : 'zoom-image.js' } ,
94
+ { name : 'disqus' , input : 'disqus.js' } ,
95
+ { name : 'gitalk' , input : 'gitalk.js' } ,
96
+ ] ;
93
97
94
98
const promises = plugins . map ( item => {
95
99
return build ( {
96
100
input : 'src/plugins/' + item . input ,
97
- output : 'plugins/' + item . name + '.js'
98
- } )
99
- } )
101
+ output : 'plugins/' + item . name + '.js' ,
102
+ } ) ;
103
+ } ) ;
100
104
101
105
if ( isProd ) {
102
106
plugins . forEach ( item => {
103
- promises . push ( build ( {
104
- input : 'src/plugins/' + item . input ,
105
- output : 'plugins/' + item . name + '.min.js' ,
106
- plugins : [ uglify ( ) ]
107
- } ) )
108
- } )
107
+ promises . push (
108
+ build ( {
109
+ input : 'src/plugins/' + item . input ,
110
+ output : 'plugins/' + item . name + '.min.js' ,
111
+ plugins : [ uglify ( ) ] ,
112
+ } )
113
+ ) ;
114
+ } ) ;
109
115
}
110
116
111
- await Promise . all ( promises )
117
+ await Promise . all ( promises ) ;
112
118
}
113
119
114
120
async function main ( ) {
@@ -118,41 +124,37 @@ async function main() {
118
124
atomic : true ,
119
125
awaitWriteFinish : {
120
126
stabilityThreshold : 1000 ,
121
- pollInterval : 100
122
- }
127
+ pollInterval : 100 ,
128
+ } ,
123
129
} )
124
130
. on ( 'change' , p => {
125
- console . log ( '[watch] ' , p )
126
- const dirs = p . split ( path . sep )
131
+ console . log ( '[watch] ' , p ) ;
132
+ const dirs = p . split ( path . sep ) ;
127
133
if ( dirs [ 1 ] === 'core' ) {
128
- buildCore ( )
134
+ buildCore ( ) ;
129
135
} else if ( dirs [ 2 ] ) {
130
- const name = path . basename ( dirs [ 2 ] , '.js' )
136
+ const name = path . basename ( dirs [ 2 ] , '.js' ) ;
131
137
const input = `src/plugins/${ name } ${
132
138
/ \. j s / . test ( dirs [ 2 ] ) ? '' : '/index'
133
- } .js`
139
+ } .js`;
134
140
135
141
build ( {
136
142
input,
137
- output : 'plugins/' + name + '.js'
138
- } )
143
+ output : 'plugins/' + name + '.js' ,
144
+ } ) ;
139
145
}
140
146
} )
141
147
. on ( 'ready' , ( ) => {
142
- console . log ( '[start]' )
143
- buildCore ( )
144
- buildAllPlugin ( )
145
- } )
148
+ console . log ( '[start]' ) ;
149
+ buildCore ( ) ;
150
+ buildAllPlugin ( ) ;
151
+ } ) ;
146
152
} else {
147
- await Promise . all ( [
148
- buildCore ( ) ,
149
- buildAllPlugin ( )
150
- ] )
153
+ await Promise . all ( [ buildCore ( ) , buildAllPlugin ( ) ] ) ;
151
154
}
152
155
}
153
156
154
- main ( ) . catch ( ( e ) => {
155
- console . error ( e )
156
- process . exit ( 1 )
157
- } )
158
-
157
+ main ( ) . catch ( e => {
158
+ console . error ( e ) ;
159
+ process . exit ( 1 ) ;
160
+ } ) ;
0 commit comments