-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
51 lines (41 loc) · 1.55 KB
/
index.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
// external dependencies
var through = require('through2'),
path = require('path');
// internal dependencies
var reactDocgenMarkdown = require('./src/react-docgen-md');
module.exports = function(options) {
options = options || {};
return through.obj(function(file, encoding, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
throw new Error('Streams not supported!')
} else if (file.isBuffer()) {
// figure out where the component headings in the markdown doc
// should link to
var pathToSrc = options.path,
srcLink;
switch (typeof pathToSrc) {
case 'string':
pathToSrc = path.resolve(pathToSrc);
srcLink = path.relative(pathToSrc, file.path);
break;
case 'function':
srcLink = pathToSrc(file.path);
break;
default:
srcLink = '';
}
// get the markdown documentation for the file
var markdownDoc = reactDocgenMarkdown(file.contents, {
componentName : file.relative.replace(file.extname, ''),
srcLink : srcLink
});
// replace the file contents and extension
file.contents = Buffer.from(markdownDoc);
file.path = file.path.replace(file.extname, '.md');
return cb(null, file);
}
});
};