Skip to content

Commit 4876ffc

Browse files
committed
Switched to q library for promises.
1 parent 7152894 commit 4876ffc

File tree

3 files changed

+74
-78
lines changed

3 files changed

+74
-78
lines changed

lib/doxdox.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var fs = require('fs'),
22
path = require('path'),
3+
q = require('q'),
34
dox = require('dox'),
45
hbs = require('handlebars'),
56
helpers = require('../lib/helpers')(hbs),
6-
Promise = require('promise'),
77
utils = require('../lib/utils');
88

99
module.exports.templates = {
@@ -55,7 +55,8 @@ module.exports.parseInput = function (input, config, pkg) {
5555

5656
module.exports.parseScripts = function (scripts, config, pkg) {
5757

58-
var files = [],
58+
var deferred = new q.defer(),
59+
files = [],
5960
content,
6061
template;
6162

@@ -100,7 +101,7 @@ module.exports.parseScripts = function (scripts, config, pkg) {
100101

101102
content.then(function (output) {
102103

103-
content = output;
104+
deferred.resolve(output);
104105

105106
});
106107

@@ -112,10 +113,6 @@ module.exports.parseScripts = function (scripts, config, pkg) {
112113

113114
}
114115

115-
return new Promise(function (resolve) {
116-
117-
resolve(content);
118-
119-
});
116+
return deferred.promise;
120117

121118
};

lib/utils.js

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,128 @@
11
var fs = require('fs'),
22
path = require('path'),
3+
q = require('q'),
34
hbs = require('handlebars'),
45
helpers = require('../lib/helpers')(hbs),
5-
Promise = require('promise'),
66
admzip = require('adm-zip'),
77
temp = require('temp').track(),
88
sqlite3 = require('sqlite3').verbose();
99

1010
module.exports.buildDashDocSet = function (input) {
1111

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');
1317

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);
1819

19-
input.uid = module.exports.formatStringForUID(input.title);
20+
input.files.forEach(function (file) {
2021

21-
input.files.forEach(function (file) {
22-
23-
file.methods.forEach(function (method) {
22+
file.methods.forEach(function (method) {
2423

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+
);
3128

3229
});
3330

34-
zip.addFile(
35-
input.title + '.docset/Contents/Info.plist',
36-
require('../templates/dash/plist.hbs')(input)
37-
);
31+
});
3832

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+
);
4337

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) {
4842

49-
});
43+
zip.addLocalFile(
44+
path.join(__dirname, '../templates/dash/resources/' + resource),
45+
input.title + '.docset/Contents/Resources/Documents/resources/' + path.dirname(resource)
46+
);
5047

51-
db.serialize(function () {
48+
});
5249

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 () {
5551

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);');
5754

58-
file.methods.forEach(function (method) {
55+
input.files.forEach(function (file) {
5956

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) {
6558

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+
});
6764

68-
method.tags.property.forEach(function (property) {
65+
if (method.tags.property) {
6966

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) {
7568

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
7673
});
7774

78-
}
75+
});
7976

80-
});
77+
}
8178

8279
});
8380

8481
});
8582

86-
db.close(function () {
83+
});
8784

88-
zip.addFile(
89-
input.title + '.docset/Contents/Resources/docSet.dsidx',
90-
fs.readFileSync(tempdb.path)
91-
);
85+
db.close(function () {
9286

93-
resolve(zip.toBuffer());
87+
zip.addFile(
88+
input.title + '.docset/Contents/Resources/docSet.dsidx',
89+
fs.readFileSync(tempdb.path)
90+
);
9491

95-
});
92+
deferred.resolve(zip.toBuffer());
9693

9794
});
9895

96+
return deferred.promise;
97+
9998
};
10099

101100

102101
module.exports.buildWiki = function (input) {
103102

104-
return new Promise(function (resolve) {
103+
var deferred = new q.defer(),
104+
zip = new admzip(),
105+
template = require('../templates/wiki/methods.hbs');
105106

106-
var zip = new admzip(),
107-
template = require('../templates/wiki/methods.hbs');
107+
input.uid = module.exports.formatStringForUID(input.title);
108108

109-
input.uid = module.exports.formatStringForUID(input.title);
109+
input.files.forEach(function (file) {
110110

111-
input.files.forEach(function (file) {
111+
file.methods.forEach(function (method) {
112112

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+
);
121117

122118
});
123119

124-
resolve(zip.toBuffer());
125-
126120
});
127121

122+
deferred.resolve(zip.toBuffer());
123+
124+
return deferred.promise;
125+
128126
};
129127

130128
module.exports.findPackagePath = function (input) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"highlight.js": "8.8.0",
1414
"markdown-it": "5.0.0",
1515
"promise": "7.0.4",
16+
"q": "1.4.1",
1617
"sqlite3": "3.1.0",
1718
"temp": "0.8.3"
1819
},

0 commit comments

Comments
 (0)