forked from eisisig/docgen-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 991 Bytes
/
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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Eisi Sig @eisisig
*/
var docgen = require('react-docgen');
var findAllComponentDefinitions = require('react-docgen/dist/resolver/findAllComponentDefinitions');
var marked = require('marked');
var loaderUtils = require('loader-utils');
if ( findAllComponentDefinitions.hasOwnProperty('default') ) {
findAllComponentDefinitions = findAllComponentDefinitions.default
}
module.exports = function ( source ) {
this.cacheable && this.cacheable();
var query = loaderUtils.parseQuery(this.query);
var value = {};
try {
value = docgen.parse(source, findAllComponentDefinitions);
if ( value && query.markdownDescription) {
value = value.map(function (doc) {
if (doc.description) {
doc.description = marked(doc.description);
}
return doc;
});
}
} catch ( e ) {
// console.log('ERROR in docgen-loader', e);
}
return "module.exports = " + JSON.stringify(value, undefined, "\t");
};