1 |
|
2 |
|
3 |
|
4 |
|
5 | var docgen = require('react-docgen');
|
6 | var findAllComponentDefinitions = require('react-docgen/dist/resolver/findAllComponentDefinitions');
|
7 | var marked = require('marked');
|
8 | var loaderUtils = require('loader-utils');
|
9 |
|
10 | if ( findAllComponentDefinitions.hasOwnProperty('default') ) {
|
11 | findAllComponentDefinitions = findAllComponentDefinitions.default
|
12 | }
|
13 |
|
14 | module.exports = function ( source ) {
|
15 |
|
16 | this.cacheable && this.cacheable();
|
17 | var query = loaderUtils.parseQuery(this.query);
|
18 |
|
19 | var value = {};
|
20 |
|
21 | try {
|
22 | value = docgen.parse(source, findAllComponentDefinitions);
|
23 | if ( value && query.markdownDescription) {
|
24 | value = value.map(function (doc) {
|
25 | if (doc.description) {
|
26 | doc.description = marked(doc.description);
|
27 | }
|
28 | return doc;
|
29 | });
|
30 | }
|
31 | } catch ( e ) {
|
32 |
|
33 | }
|
34 |
|
35 | return "module.exports = " + JSON.stringify(value, undefined, "\t");
|
36 | };
|