UNPKG

991 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Eisi Sig @eisisig
4 */
5var docgen = require('react-docgen');
6var findAllComponentDefinitions = require('react-docgen/dist/resolver/findAllComponentDefinitions');
7var marked = require('marked');
8var loaderUtils = require('loader-utils');
9
10if ( findAllComponentDefinitions.hasOwnProperty('default') ) {
11 findAllComponentDefinitions = findAllComponentDefinitions.default
12}
13
14module.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 // console.log('ERROR in docgen-loader', e);
33 }
34
35 return "module.exports = " + JSON.stringify(value, undefined, "\t");
36};