-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
docmeify.js
57 lines (44 loc) · 1.44 KB
/
docmeify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var log = require('npmlog')
, mutiny = require('mutiny')
, pruneHtml = require('prune-html')
, transformify = require('transformify')
var stream = require('stream')
, util = require('util');
var Writable = stream.Writable;
util.inherits(MutinyWritable, Writable);
function MutinyWritable (opts) {
if (!(this instanceof MutinyWritable)) return new MutinyWritable(opts);
opts = opts || {};
Writable.call(this, opts);
this.apidocs = '';
}
MutinyWritable.prototype._write = function (chunk, encoding, cb) {
this.apidocs += chunk;
cb();
}
var go = module.exports =
/**
* Generates github readme compatible `*.API.md` files from `*.html` jsdoc files
*
* @name docmeify
* @private
* @function
* @param {String} htmldir
* @param {Function(Error, String)} cb called back with entire API section that was converted
*/
function docmeify(htmldir, cb) {
var outstream = new MutinyWritable()
, pruneTransform = transformify(pruneHtml.bind(null, [ 'h1', 'h2', 'h3', 'header' ]));
function onend() {
cb(null, outstream.apidocs);
}
log.verbose('docme', 'githubifying the jsdoc generated pages');
mutiny(
{ getOutStream: function (file) { return outstream }, transform: [ 'jsdoc-githubify', pruneTransform ] }
, { root: htmldir, fileFilter: '*.html' }
)
.on('error', cb)
.on('data', function (d) { log.verbose('docme', 'Processed:\n', d); })
.on('end', onend)
};