@@ -2,94 +2,87 @@ var fs = require('fs'),
2
2
path = require ( 'path' ) ,
3
3
hbs = require ( 'handlebars' ) ,
4
4
helpers = require ( '../lib/helpers' ) ( hbs ) ,
5
+ Promise = require ( 'promise' ) ,
5
6
admzip = require ( 'adm-zip' ) ,
6
7
temp = require ( 'temp' ) . track ( ) ,
7
8
sqlite3 = require ( 'sqlite3' ) . verbose ( ) ;
8
9
9
10
module . exports . buildDashDocSet = function ( input ) {
10
11
11
- var zip = new admzip ( ) ,
12
- tempdb = temp . openSync ( 'temp.sqlite' ) ,
13
- db = new sqlite3 . Database ( tempdb . path ) ;
12
+ return new Promise ( function ( resolve ) {
14
13
15
- input . uid = module . exports . formatStringForUID ( input . title ) ;
14
+ var zip = new admzip ( ) ,
15
+ tempdb = temp . openSync ( 'temp.sqlite' ) ,
16
+ db = new sqlite3 . Database ( tempdb . path ) ;
16
17
17
- zip . addFile (
18
- input . title + '.docset/Contents/Resources/Documents/index.html' ,
19
- require ( '../templates/dash/index.hbs' ) ( input )
20
- ) ;
18
+ input . uid = module . exports . formatStringForUID ( input . title ) ;
21
19
22
- zip . addFile (
23
- input . title + '.docset/Contents/Info.plist' ,
24
- require ( '../templates/dash/plist.hbs' ) ( input )
25
- ) ;
26
-
27
- [
28
- 'bootstrap/bootstrap.min.css' ,
29
- 'highlight.js/github.min.css'
30
- ] . forEach ( function ( resource ) {
31
-
32
- zip . addLocalFile (
33
- path . join ( __dirname , '../templates/dash/resources/' + resource ) ,
34
- input . title + '.docset/Contents/Resources/Documents/resources/' + path . dirname ( resource )
20
+ zip . addFile (
21
+ input . title + '.docset/Contents/Resources/Documents/index.html' ,
22
+ require ( '../templates/dash/index.hbs' ) ( input )
35
23
) ;
36
24
37
- } ) ;
25
+ zip . addFile (
26
+ input . title + '.docset/Contents/Info.plist' ,
27
+ require ( '../templates/dash/plist.hbs' ) ( input )
28
+ ) ;
38
29
39
- db . serialize ( function ( ) {
30
+ [
31
+ 'bootstrap/bootstrap.min.css' ,
32
+ 'highlight.js/github.min.css'
33
+ ] . forEach ( function ( resource ) {
40
34
41
- db . run ( 'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);' ) ;
42
- db . run ( 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);' ) ;
35
+ zip . addLocalFile (
36
+ path . join ( __dirname , '../templates/dash/resources/' + resource ) ,
37
+ input . title + '.docset/Contents/Resources/Documents/resources/' + path . dirname ( resource )
38
+ ) ;
43
39
44
- input . files . forEach ( function ( file ) {
40
+ } ) ;
45
41
46
- file . methods . forEach ( function ( method ) {
42
+ db . serialize ( function ( ) {
47
43
48
- if ( ! method . ignore && method . ctx ) {
44
+ db . run ( 'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);' ) ;
45
+ db . run ( 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);' ) ;
49
46
50
- db . run ( 'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);' , {
51
- $name : hbs . helpers . formatName ( method . ctx . string ) ,
52
- $type : method . ctx . type . replace ( / ^ [ a - z ] / , function ( match ) { return match . toUpperCase ( ) ; } ) ,
53
- $path : 'index.html#' + method . ctx . uid
54
- } ) ;
47
+ input . files . forEach ( function ( file ) {
55
48
56
- }
49
+ file . methods . forEach ( function ( method ) {
57
50
58
- } ) ;
51
+ if ( ! method . ignore && method . ctx ) {
59
52
60
- } ) ;
53
+ db . run ( 'INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);' , {
54
+ $name : hbs . helpers . formatName ( method . ctx . string ) ,
55
+ $type : method . ctx . type . replace ( / ^ [ a - z ] / , function ( match ) { return match . toUpperCase ( ) ; } ) ,
56
+ $path : 'index.html#' + method . ctx . uid
57
+ } ) ;
61
58
62
- } ) ;
59
+ }
63
60
64
- db . close ( function ( ) {
61
+ } ) ;
65
62
66
- zip . addFile (
67
- input . title + '.docset/Contents/Resources/docSet.dsidx' ,
68
- fs . readFileSync ( tempdb . path )
69
- ) ;
70
-
71
- if ( input . output ) {
72
-
73
- fs . writeFileSync ( input . output , zip . toBuffer ( ) , 'utf8' ) ;
63
+ } ) ;
74
64
75
- }
65
+ } ) ;
76
66
77
- } ) ;
67
+ db . close ( function ( ) {
78
68
79
- if ( ! input . output ) {
69
+ zip . addFile (
70
+ input . title + '.docset/Contents/Resources/docSet.dsidx' ,
71
+ fs . readFileSync ( tempdb . path )
72
+ ) ;
80
73
81
- console . error ( 'Not avalible through stdout. Please use the --output flag instead.' ) ;
74
+ resolve ( zip . toBuffer ( ) ) ;
82
75
83
- }
76
+ } ) ;
84
77
85
- return false ;
78
+ } ) ;
86
79
87
80
} ;
88
81
89
82
module . exports . findPackage = function ( input ) {
90
83
91
- var stat ,
92
- pkg ;
84
+ var pkg ,
85
+ stat ;
93
86
94
87
if ( fs . existsSync ( input ) ) {
95
88
@@ -160,25 +153,25 @@ module.exports.parseData = function (data, file) {
160
153
161
154
} ;
162
155
163
- module . exports . walk = function ( dir , opts ) {
156
+ module . exports . walk = function ( dir , options ) {
164
157
165
158
var files = [ ] ;
166
159
167
- if ( ! opts ) {
160
+ if ( ! options ) {
168
161
169
- opts = { } ;
162
+ options = { } ;
170
163
171
164
}
172
165
173
- if ( ! opts . match ) {
166
+ if ( ! options . match ) {
174
167
175
- opts . match = / \. j s $ / ;
168
+ options . match = / \. j s $ / ;
176
169
177
170
}
178
171
179
- if ( ! opts . exception ) {
172
+ if ( ! options . exception ) {
180
173
181
- opts . exception = / \. g i t | \. m i n | n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s | t e s t | g r u n t f i l e | g u l p f i l e / i;
174
+ options . exception = / \. g i t | \. m i n | n o d e _ m o d u l e s | b o w e r _ c o m p o n e n t s | t e s t | g r u n t f i l e | g u l p f i l e / i;
182
175
183
176
}
184
177
@@ -192,11 +185,11 @@ module.exports.walk = function (dir, opts) {
192
185
193
186
stat = fs . statSync ( file ) ;
194
187
195
- if ( stat . isDirectory ( ) && ! file . match ( opts . exception ) ) {
188
+ if ( stat . isDirectory ( ) && ! file . match ( options . exception ) ) {
196
189
197
- files = files . concat ( module . exports . walk ( file , opts ) ) ;
190
+ files = files . concat ( module . exports . walk ( file , options ) ) ;
198
191
199
- } else if ( stat . isFile ( ) && file . match ( opts . match ) && ! file . match ( opts . exception ) ) {
192
+ } else if ( stat . isFile ( ) && file . match ( options . match ) && ! file . match ( options . exception ) ) {
200
193
201
194
files . push ( file ) ;
202
195
0 commit comments