Skip to content

Commit 81f961a

Browse files
committed
Updated doxdox to be importable through Node.js
1 parent 64bec12 commit 81f961a

File tree

3 files changed

+68
-57
lines changed

3 files changed

+68
-57
lines changed

bin/doxdox

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

33
var pkg = require('../package'),
4-
fs = require('fs'),
54
chalk = require('chalk'),
6-
dox = require('dox'),
7-
hbs = require('handlebars'),
8-
helpers = require('../lib/helpers')(hbs),
9-
utils = require('../lib/utils');
10-
11-
var templates = {
12-
bootstrap: require('../templates/bootstrap.hbs'),
13-
markdown: require('../templates/markdown.hbs')
5+
doxdox = require('..');
6+
7+
var config = {
8+
title: 'Untitled Project',
9+
description: '',
10+
layout: 'bootstrap'
1411
};
1512

16-
var title = 'Untitled Project',
17-
description = '',
18-
layout = 'bootstrap',
19-
script = '',
13+
var script = '',
2014
output = '';
2115

2216
var args = process.argv.slice(2),
@@ -36,17 +30,17 @@ while (args.length) {
3630

3731
case '-t':
3832
case '--title':
39-
title = args.shift();
33+
config.title = args.shift();
4034
break;
4135

4236
case '-d':
4337
case '--description':
44-
description = args.shift();
38+
config.description = args.shift();
4539
break;
4640

4741
case '-l':
4842
case '--layout':
49-
layout = args.shift();
43+
config.layout = args.shift();
5044
break;
5145

5246
case '-o':
@@ -69,7 +63,6 @@ while (args.length) {
6963
process.stdout.write(chalk.yellow(' -t, --title') + '\t\tSets title.' + '\n');
7064
process.stdout.write(chalk.yellow(' -d, --description') + '\tSets description.' + '\n');
7165
process.stdout.write(chalk.yellow(' -l, --layout') + '\t\tTemplate to render the documentation with.' + '\n');
72-
process.stdout.write(chalk.yellow(' -l, --layout') + '\t\tTemplate to render the documentation with.' + '\n');
7366
process.stdout.write(chalk.yellow(' -o, --output') + '\t\tFile to save documentation to. Default to stdout.' + '\n');
7467
process.stdout.write('\n');
7568
process.stdout.write(' Available Layouts:' + '\n\n');
@@ -83,43 +76,4 @@ while (args.length) {
8376

8477
}
8578

86-
fs.exists(script, function (exists) {
87-
88-
var content,
89-
data;
90-
91-
if (exists) {
92-
93-
data = dox.parseComments(fs.readFileSync(script, 'utf8'));
94-
95-
if (templates[layout]) {
96-
97-
content = templates[layout]({
98-
title: title,
99-
description: description,
100-
methods: utils.parseData(data)
101-
});
102-
103-
if (output) {
104-
105-
fs.writeFileSync(output, content, 'utf8');
106-
107-
} else {
108-
109-
process.stdout.write(content);
110-
111-
}
112-
113-
} else {
114-
115-
process.stdout.write('Invalid layout specified.' + '\n');
116-
117-
}
118-
119-
} else {
120-
121-
process.stdout.write('File not found.' + '\n');
122-
123-
}
124-
125-
});
79+
doxdox.parseScript(script, output, config);

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/doxdox');

lib/doxdox.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var fs = require('fs'),
2+
dox = require('dox'),
3+
hbs = require('handlebars'),
4+
helpers = require('../lib/helpers')(hbs),
5+
utils = require('../lib/utils');
6+
7+
var templates = {
8+
bootstrap: require('../templates/bootstrap.hbs'),
9+
markdown: require('../templates/markdown.hbs')
10+
};
11+
12+
exports.parseScript = function (script, output, config) {
13+
14+
fs.exists(script, function (exists) {
15+
16+
var content,
17+
data;
18+
19+
if (exists) {
20+
21+
data = dox.parseComments(fs.readFileSync(script, 'utf8'));
22+
23+
if (templates[config.layout]) {
24+
25+
content = templates[config.layout]({
26+
title: config.title,
27+
description: config.description,
28+
methods: utils.parseData(data)
29+
});
30+
31+
if (output) {
32+
33+
fs.writeFileSync(output, content, 'utf8');
34+
35+
} else {
36+
37+
process.stdout.write(content);
38+
39+
}
40+
41+
} else {
42+
43+
process.stdout.write('Invalid layout specified.' + '\n');
44+
45+
}
46+
47+
} else {
48+
49+
process.stdout.write('File not found.' + '\n');
50+
51+
}
52+
53+
});
54+
55+
}
56+

0 commit comments

Comments
 (0)