Skip to content

Commit 50c0528

Browse files
committed
Merge branch 'feature/promise'
2 parents 67de0cd + 23a09d0 commit 50c0528

File tree

6 files changed

+90
-87
lines changed

6 files changed

+90
-87
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
node_modules/
2-
templates/bootstrap.min.js

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![](https://david-dm.org/neogeek/doxdox.svg)](https://david-dm.org/neogeek/doxdox/) [![](http://img.shields.io/npm/v/doxdox.svg)](https://www.npmjs.org/package/doxdox)
1+
[![](https://david-dm.org/neogeek/doxdox.svg?style=flat)](https://david-dm.org/neogeek/doxdox/) [![](http://img.shields.io/npm/v/doxdox.svg?style=flat)](https://www.npmjs.org/package/doxdox)
22

33
#doxdox
44

@@ -34,12 +34,6 @@ $ npm install doxdox -g
3434
- Dash (http://kapeli.com/docsets/)
3535
```
3636

37-
##Exporting
38-
39-
###Dash
40-
41-
Exporting to Dash generates a zip file and is only available through the `--output` flag.
42-
4337
##Examples:
4438

4539
- [Facade.js](http://facadejs.com/) - [Documentation](http://docs.facadejs.com/)

bin/doxdox

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env node
22

33
var fs = require('fs'),
4-
path = require('path'),
54
chalk = require('chalk'),
65
doxdox = require('..'),
76
utils = require('../lib/utils');
@@ -87,6 +86,7 @@ while (args.length) {
8786
process.stdout.write(' Available Layouts:' + '\n\n');
8887
process.stdout.write(' - Bootstrap (default)\t (http://getbootstrap.com/)' + '\n');
8988
process.stdout.write(' - Markdown\t\t (http://daringfireball.net/projects/markdown/)' + '\n');
89+
process.stdout.write(' - Dash\t\t (http://kapeli.com/docsets/)' + '\n');
9090
process.stdout.write('\n');
9191
process.kill();
9292

@@ -126,4 +126,16 @@ if (!config.title) {
126126

127127
}
128128

129-
doxdox.parseInput(input, output, config);
129+
doxdox.parseInput(input, config).then(function (content) {
130+
131+
if (output) {
132+
133+
fs.writeFileSync(output, content, 'utf8');
134+
135+
} else {
136+
137+
process.stdout.write(content);
138+
139+
}
140+
141+
});

lib/doxdox.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require('fs'),
33
dox = require('dox'),
44
hbs = require('handlebars'),
55
helpers = require('../lib/helpers')(hbs),
6+
Promise = require('promise'),
67
utils = require('../lib/utils');
78

89
var templates = {
@@ -11,7 +12,7 @@ var templates = {
1112
dash: utils.buildDashDocSet
1213
};
1314

14-
exports.parseInput = function (input, output, config) {
15+
exports.parseInput = function (input, config) {
1516

1617
var files = [],
1718
stat;
@@ -47,11 +48,11 @@ exports.parseInput = function (input, output, config) {
4748

4849
}
4950

50-
return exports.parseScripts(files, output, config);
51+
return exports.parseScripts(files, config);
5152

5253
};
5354

54-
exports.parseScripts = function (scripts, output, config) {
55+
exports.parseScripts = function (scripts, config) {
5556

5657
var files = [],
5758
content,
@@ -87,26 +88,29 @@ exports.parseScripts = function (scripts, output, config) {
8788
content = template({
8889
title: config.title,
8990
description: config.description,
90-
files: files,
91-
output: output
91+
files: files
9292
});
9393

94-
if (output) {
94+
if (typeof content.then === 'function') {
9595

96-
fs.writeFileSync(output, content, 'utf8');
96+
content.then(function (output) {
9797

98-
} else {
98+
content = output;
9999

100-
process.stdout.write(content);
100+
});
101101

102102
}
103103

104-
return content;
105-
106104
} else {
107105

108-
process.stdout.write('Invalid layout specified.' + '\n');
106+
console.error('Invalid layout specified.' + '\n');
109107

110108
}
111109

112-
}
110+
return new Promise(function (resolve) {
111+
112+
resolve(content);
113+
114+
});
115+
116+
};

lib/utils.js

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,87 @@ var fs = require('fs'),
22
path = require('path'),
33
hbs = require('handlebars'),
44
helpers = require('../lib/helpers')(hbs),
5+
Promise = require('promise'),
56
admzip = require('adm-zip'),
67
temp = require('temp').track(),
78
sqlite3 = require('sqlite3').verbose();
89

910
module.exports.buildDashDocSet = function (input) {
1011

11-
var zip = new admzip(),
12-
tempdb = temp.openSync('temp.sqlite'),
13-
db = new sqlite3.Database(tempdb.path);
12+
return new Promise(function (resolve) {
1413

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

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

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)
3523
);
3624

37-
});
25+
zip.addFile(
26+
input.title + '.docset/Contents/Info.plist',
27+
require('../templates/dash/plist.hbs')(input)
28+
);
3829

39-
db.serialize(function () {
30+
[
31+
'bootstrap/bootstrap.min.css',
32+
'highlight.js/github.min.css'
33+
].forEach(function (resource) {
4034

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

44-
input.files.forEach(function (file) {
40+
});
4541

46-
file.methods.forEach(function (method) {
42+
db.serialize(function () {
4743

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

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

56-
}
49+
file.methods.forEach(function (method) {
5750

58-
});
51+
if (!method.ignore && method.ctx) {
5952

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

62-
});
59+
}
6360

64-
db.close(function () {
61+
});
6562

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

75-
}
65+
});
7666

77-
});
67+
db.close(function () {
7868

79-
if (!input.output) {
69+
zip.addFile(
70+
input.title + '.docset/Contents/Resources/docSet.dsidx',
71+
fs.readFileSync(tempdb.path)
72+
);
8073

81-
console.error('Not avalible through stdout. Please use the --output flag instead.');
74+
resolve(zip.toBuffer());
8275

83-
}
76+
});
8477

85-
return false;
78+
});
8679

8780
};
8881

8982
module.exports.findPackage = function (input) {
9083

91-
var stat,
92-
pkg;
84+
var pkg,
85+
stat;
9386

9487
if (fs.existsSync(input)) {
9588

@@ -160,25 +153,25 @@ module.exports.parseData = function (data, file) {
160153

161154
};
162155

163-
module.exports.walk = function (dir, opts) {
156+
module.exports.walk = function (dir, options) {
164157

165158
var files = [];
166159

167-
if (!opts) {
160+
if (!options) {
168161

169-
opts = {};
162+
options = {};
170163

171164
}
172165

173-
if (!opts.match) {
166+
if (!options.match) {
174167

175-
opts.match = /\.js$/;
168+
options.match = /\.js$/;
176169

177170
}
178171

179-
if (!opts.exception) {
172+
if (!options.exception) {
180173

181-
opts.exception = /\.git|\.min|node_modules|bower_components|test|gruntfile|gulpfile/i;
174+
options.exception = /\.git|\.min|node_modules|bower_components|test|gruntfile|gulpfile/i;
182175

183176
}
184177

@@ -192,11 +185,11 @@ module.exports.walk = function (dir, opts) {
192185

193186
stat = fs.statSync(file);
194187

195-
if (stat.isDirectory() && !file.match(opts.exception)) {
188+
if (stat.isDirectory() && !file.match(options.exception)) {
196189

197-
files = files.concat(module.exports.walk(file, opts));
190+
files = files.concat(module.exports.walk(file, options));
198191

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

201194
files.push(file);
202195

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dox": "0.6.1",
1010
"handlebars": "2.0.0",
1111
"highlight.js": "8.4.0",
12+
"promise": "6.0.1",
1213
"sqlite3": "3.0.4",
1314
"adm-zip": "0.4.4",
1415
"temp": "0.8.1"

0 commit comments

Comments
 (0)