@@ -18,129 +18,174 @@ const sqlite3 = require('sqlite3').verbose();
18
18
* @public
19
19
*/
20
20
21
- const plugin = data => new Promise ( ( resolve , reject ) => {
21
+ const plugin = data =>
22
+ new Promise ( ( resolve , reject ) => {
22
23
23
- const zip = new admzip ( ) ;
24
- const tempdb = temp . openSync ( 'temp.sqlite' ) ;
25
- const db = new sqlite3 . Database ( tempdb . path ) ;
24
+ const zip = new admzip ( ) ;
25
+ const tempdb = temp . openSync ( 'temp.sqlite' ) ;
26
+ const db = new sqlite3 . Database ( tempdb . path ) ;
26
27
27
- fs . readFile ( path . join ( __dirname , 'templates/method.hbs' ) , 'utf8' , ( err , contents ) => {
28
+ fs . readFile (
29
+ path . join ( __dirname , 'templates/method.hbs' ) ,
30
+ 'utf8' ,
31
+ ( err , contents ) => {
28
32
29
- if ( err ) {
30
-
31
- return reject ( err ) ;
32
-
33
- }
34
-
35
- const methodTemplate = Handlebars . compile ( contents ) ;
36
-
37
- fs . readFile ( path . join ( __dirname , 'templates/Info.plist.hbs' ) , 'utf8' , ( err , contents ) => {
38
-
39
- if ( err ) {
40
-
41
- return reject ( err ) ;
42
-
43
- }
44
-
45
- const plistTemplate = Handlebars . compile ( contents ) ;
33
+ if ( err ) {
46
34
47
- zip . addFile (
48
- `${ data . title } .docset/Contents/Info.plist` ,
49
- plistTemplate ( data )
50
- ) ;
35
+ return reject ( err ) ;
51
36
52
- zip . addLocalFile (
53
- path . join ( __dirname , 'templates/resources/bootstrap.min.css' ) ,
54
- `${ data . title } .docset/Contents/Resources/Documents/resources/`
55
- ) ;
37
+ }
56
38
57
- zip . addLocalFile (
58
- path . join ( __dirname , 'templates/resources/documentation.css' ) ,
59
- `${ data . title } .docset/Contents/Resources/Documents/resources/`
60
- ) ;
39
+ const methodTemplate = Handlebars . compile ( contents ) ;
61
40
62
- zip . addLocalFile (
63
- path . join ( __dirname , 'templates/resources/github.min.css ' ) ,
64
- ` ${ data . title } .docset/Contents/Resources/Documents/resources/`
65
- ) ;
41
+ fs . readFile (
42
+ path . join ( __dirname , 'templates/Info.plist.hbs ' ) ,
43
+ 'utf8' ,
44
+ ( err , contents ) => {
66
45
67
- db . serialize ( ( ) => {
46
+ if ( err ) {
68
47
69
- db . run ( 'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);' ) ;
70
- db . run ( 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);' ) ;
48
+ return reject ( err ) ;
71
49
72
- data . files . forEach ( file => {
50
+ }
73
51
74
- file . methods . forEach ( method => {
52
+ const plistTemplate = Handlebars . compile ( contents ) ;
75
53
76
54
zip . addFile (
77
- `${ data . title } .docset/Contents/Resources/Documents/ ${ method . uid } .html ` ,
78
- methodTemplate ( method )
55
+ `${ data . title } .docset/Contents/Info.plist ` ,
56
+ plistTemplate ( data )
79
57
) ;
80
58
81
- db . run ( 'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);' , {
82
- '$name' : method . name ,
83
- '$path' : `${ method . uid } .html` ,
84
- '$type' : method . type . replace ( / ^ [ a - z ] / , match => match . toUpperCase ( ) )
85
- } ) ;
59
+ zip . addLocalFile (
60
+ path . join (
61
+ __dirname ,
62
+ 'templates/resources/bootstrap.min.css'
63
+ ) ,
64
+ `${
65
+ data . title
66
+ } .docset/Contents/Resources/Documents/resources/`
67
+ ) ;
86
68
87
- if ( method . tags . property ) {
69
+ zip . addLocalFile (
70
+ path . join (
71
+ __dirname ,
72
+ 'templates/resources/documentation.css'
73
+ ) ,
74
+ `${
75
+ data . title
76
+ } .docset/Contents/Resources/Documents/resources/`
77
+ ) ;
88
78
89
- method . tags . property . forEach ( property => {
79
+ zip . addLocalFile (
80
+ path . join (
81
+ __dirname ,
82
+ 'templates/resources/github.min.css'
83
+ ) ,
84
+ `${
85
+ data . title
86
+ } .docset/Contents/Resources/Documents/resources/`
87
+ ) ;
88
+
89
+ db . serialize ( ( ) => {
90
+
91
+ db . run ( 'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);' ) ;
92
+ db . run ( 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);' ) ;
93
+
94
+ data . files . forEach ( file => {
95
+
96
+ file . methods . forEach ( method => {
97
+
98
+ zip . addFile (
99
+ `${
100
+ data . title
101
+ } .docset/Contents/Resources/Documents/${
102
+ method . uid
103
+ } .html`,
104
+ methodTemplate ( method )
105
+ ) ;
106
+
107
+ db . run (
108
+ 'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);' ,
109
+ {
110
+ '$name' : method . name ,
111
+ '$path' : `${ method . uid } .html` ,
112
+ '$type' : method . type . replace (
113
+ / ^ [ a - z ] / u,
114
+ match => match . toUpperCase ( )
115
+ )
116
+ }
117
+ ) ;
118
+
119
+ if ( method . tags . property ) {
120
+
121
+ method . tags . property . forEach ( property => {
122
+
123
+ db . run (
124
+ 'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);' ,
125
+ {
126
+ '$name' : `${
127
+ method . name
128
+ } .${ property . name } `,
129
+ '$path' : `${
130
+ method . uid
131
+ } .html#//apple_ref/cpp/Property/${
132
+ property . name
133
+ } `,
134
+ '$type' : 'Property'
135
+ }
136
+ ) ;
137
+
138
+ } ) ;
139
+
140
+ }
90
141
91
- db . run ( 'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);' , {
92
- '$name' : `${ method . name } .${ property . name } ` ,
93
- '$path' : `${ method . uid } .html#//apple_ref/cpp/Property/${ property . name } ` ,
94
- '$type' : 'Property'
95
142
} ) ;
96
143
97
144
} ) ;
98
145
99
- }
100
-
101
- } ) ;
102
-
103
- } ) ;
146
+ } ) ;
104
147
105
- } ) ;
148
+ db . close ( err => {
106
149
107
- db . close ( err => {
150
+ if ( err ) {
108
151
109
- if ( err ) {
152
+ return reject ( err ) ;
110
153
111
- return reject ( err ) ;
154
+ }
112
155
113
- }
156
+ fs . readFile ( tempdb . path , ( err , contents ) => {
114
157
115
- fs . readFile ( tempdb . path , ( err , contents ) => {
158
+ if ( err ) {
116
159
117
- if ( err ) {
160
+ return reject ( err ) ;
118
161
119
- return reject ( err ) ;
162
+ }
120
163
121
- }
164
+ zip . addFile (
165
+ `${
166
+ data . title
167
+ } .docset/Contents/Resources/docSet.dsidx`,
168
+ contents
169
+ ) ;
122
170
123
- zip . addFile (
124
- `${ data . title } .docset/Contents/Resources/docSet.dsidx` ,
125
- contents
126
- ) ;
171
+ return resolve ( zip . toBuffer ( ) ) ;
127
172
128
- return resolve ( zip . toBuffer ( ) ) ;
173
+ } ) ;
129
174
130
- } ) ;
175
+ return false ;
131
176
132
- return false ;
177
+ } ) ;
133
178
134
- } ) ;
179
+ return false ;
135
180
136
- return false ;
181
+ }
182
+ ) ;
137
183
138
- } ) ;
184
+ return false ;
139
185
140
- return false ;
186
+ }
187
+ ) ;
141
188
142
189
} ) ;
143
190
144
- } ) ;
145
-
146
191
module . exports = plugin ;
0 commit comments