|
1 | 1 | var fs = require('fs'),
|
2 | 2 | path = require('path'),
|
| 3 | + q = require('q'), |
3 | 4 | hbs = require('handlebars'),
|
4 | 5 | helpers = require('../lib/helpers')(hbs),
|
5 |
| - Promise = require('promise'), |
6 | 6 | admzip = require('adm-zip'),
|
7 | 7 | temp = require('temp').track(),
|
8 | 8 | sqlite3 = require('sqlite3').verbose();
|
9 | 9 |
|
10 | 10 | module.exports.buildDashDocSet = function (input) {
|
11 | 11 |
|
12 |
| - return new Promise(function (resolve) { |
| 12 | + var deferred = new q.defer(), |
| 13 | + zip = new admzip(), |
| 14 | + tempdb = temp.openSync('temp.sqlite'), |
| 15 | + db = new sqlite3.Database(tempdb.path), |
| 16 | + template = require('../templates/dash/method.hbs'); |
13 | 17 |
|
14 |
| - var zip = new admzip(), |
15 |
| - tempdb = temp.openSync('temp.sqlite'), |
16 |
| - db = new sqlite3.Database(tempdb.path), |
17 |
| - template = require('../templates/dash/method.hbs'); |
| 18 | + input.uid = module.exports.formatStringForUID(input.title); |
18 | 19 |
|
19 |
| - input.uid = module.exports.formatStringForUID(input.title); |
| 20 | + input.files.forEach(function (file) { |
20 | 21 |
|
21 |
| - input.files.forEach(function (file) { |
22 |
| - |
23 |
| - file.methods.forEach(function (method) { |
| 22 | + file.methods.forEach(function (method) { |
24 | 23 |
|
25 |
| - zip.addFile( |
26 |
| - input.title + '.docset/Contents/Resources/Documents/' + method.uid + '.html', |
27 |
| - template(method) |
28 |
| - ); |
29 |
| - |
30 |
| - }); |
| 24 | + zip.addFile( |
| 25 | + input.title + '.docset/Contents/Resources/Documents/' + method.uid + '.html', |
| 26 | + template(method) |
| 27 | + ); |
31 | 28 |
|
32 | 29 | });
|
33 | 30 |
|
34 |
| - zip.addFile( |
35 |
| - input.title + '.docset/Contents/Info.plist', |
36 |
| - require('../templates/dash/plist.hbs')(input) |
37 |
| - ); |
| 31 | + }); |
38 | 32 |
|
39 |
| - [ |
40 |
| - 'bootstrap/bootstrap.min.css', |
41 |
| - 'highlight.js/github.min.css' |
42 |
| - ].forEach(function (resource) { |
| 33 | + zip.addFile( |
| 34 | + input.title + '.docset/Contents/Info.plist', |
| 35 | + require('../templates/dash/plist.hbs')(input) |
| 36 | + ); |
43 | 37 |
|
44 |
| - zip.addLocalFile( |
45 |
| - path.join(__dirname, '../templates/dash/resources/' + resource), |
46 |
| - input.title + '.docset/Contents/Resources/Documents/resources/' + path.dirname(resource) |
47 |
| - ); |
| 38 | + [ |
| 39 | + 'bootstrap/bootstrap.min.css', |
| 40 | + 'highlight.js/github.min.css' |
| 41 | + ].forEach(function (resource) { |
48 | 42 |
|
49 |
| - }); |
| 43 | + zip.addLocalFile( |
| 44 | + path.join(__dirname, '../templates/dash/resources/' + resource), |
| 45 | + input.title + '.docset/Contents/Resources/Documents/resources/' + path.dirname(resource) |
| 46 | + ); |
50 | 47 |
|
51 |
| - db.serialize(function () { |
| 48 | + }); |
52 | 49 |
|
53 |
| - db.run('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);'); |
54 |
| - db.run('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);'); |
| 50 | + db.serialize(function () { |
55 | 51 |
|
56 |
| - input.files.forEach(function (file) { |
| 52 | + db.run('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);'); |
| 53 | + db.run('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);'); |
57 | 54 |
|
58 |
| - file.methods.forEach(function (method) { |
| 55 | + input.files.forEach(function (file) { |
59 | 56 |
|
60 |
| - db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', { |
61 |
| - $name: method.name, |
62 |
| - $type: method.type.replace(/^[a-z]/, function (match) { return match.toUpperCase(); }), |
63 |
| - $path: method.uid + '.html' |
64 |
| - }); |
| 57 | + file.methods.forEach(function (method) { |
65 | 58 |
|
66 |
| - if (method.tags.property) { |
| 59 | + db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', { |
| 60 | + $name: method.name, |
| 61 | + $type: method.type.replace(/^[a-z]/, function (match) { return match.toUpperCase(); }), |
| 62 | + $path: method.uid + '.html' |
| 63 | + }); |
67 | 64 |
|
68 |
| - method.tags.property.forEach(function (property) { |
| 65 | + if (method.tags.property) { |
69 | 66 |
|
70 |
| - db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', { |
71 |
| - $name: method.name + '.' + property.name, |
72 |
| - $type: 'Property', |
73 |
| - $path: method.uid + '.html#//apple_ref/cpp/Property/' + property.name |
74 |
| - }); |
| 67 | + method.tags.property.forEach(function (property) { |
75 | 68 |
|
| 69 | + db.run('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ($name, $type, $path);', { |
| 70 | + $name: method.name + '.' + property.name, |
| 71 | + $type: 'Property', |
| 72 | + $path: method.uid + '.html#//apple_ref/cpp/Property/' + property.name |
76 | 73 | });
|
77 | 74 |
|
78 |
| - } |
| 75 | + }); |
79 | 76 |
|
80 |
| - }); |
| 77 | + } |
81 | 78 |
|
82 | 79 | });
|
83 | 80 |
|
84 | 81 | });
|
85 | 82 |
|
86 |
| - db.close(function () { |
| 83 | + }); |
87 | 84 |
|
88 |
| - zip.addFile( |
89 |
| - input.title + '.docset/Contents/Resources/docSet.dsidx', |
90 |
| - fs.readFileSync(tempdb.path) |
91 |
| - ); |
| 85 | + db.close(function () { |
92 | 86 |
|
93 |
| - resolve(zip.toBuffer()); |
| 87 | + zip.addFile( |
| 88 | + input.title + '.docset/Contents/Resources/docSet.dsidx', |
| 89 | + fs.readFileSync(tempdb.path) |
| 90 | + ); |
94 | 91 |
|
95 |
| - }); |
| 92 | + deferred.resolve(zip.toBuffer()); |
96 | 93 |
|
97 | 94 | });
|
98 | 95 |
|
| 96 | + return deferred.promise; |
| 97 | + |
99 | 98 | };
|
100 | 99 |
|
101 | 100 |
|
102 | 101 | module.exports.buildWiki = function (input) {
|
103 | 102 |
|
104 |
| - return new Promise(function (resolve) { |
| 103 | + var deferred = new q.defer(), |
| 104 | + zip = new admzip(), |
| 105 | + template = require('../templates/wiki/methods.hbs'); |
105 | 106 |
|
106 |
| - var zip = new admzip(), |
107 |
| - template = require('../templates/wiki/methods.hbs'); |
| 107 | + input.uid = module.exports.formatStringForUID(input.title); |
108 | 108 |
|
109 |
| - input.uid = module.exports.formatStringForUID(input.title); |
| 109 | + input.files.forEach(function (file) { |
110 | 110 |
|
111 |
| - input.files.forEach(function (file) { |
| 111 | + file.methods.forEach(function (method) { |
112 | 112 |
|
113 |
| - file.methods.forEach(function (method) { |
114 |
| - |
115 |
| - zip.addFile( |
116 |
| - file.name + '/' + method.name + '.md', |
117 |
| - template(method) |
118 |
| - ); |
119 |
| - |
120 |
| - }); |
| 113 | + zip.addFile( |
| 114 | + file.name + '/' + method.name + '.md', |
| 115 | + template(method) |
| 116 | + ); |
121 | 117 |
|
122 | 118 | });
|
123 | 119 |
|
124 |
| - resolve(zip.toBuffer()); |
125 |
| - |
126 | 120 | });
|
127 | 121 |
|
| 122 | + deferred.resolve(zip.toBuffer()); |
| 123 | + |
| 124 | + return deferred.promise; |
| 125 | + |
128 | 126 | };
|
129 | 127 |
|
130 | 128 | module.exports.findPackagePath = function (input) {
|
|
0 commit comments