Ejemplo n.º 1
0
function genDoc(src) {
  let componentInfo;
  let dependency;
  try {
    componentInfo = docs.parse(src);
    dependency = detective(src)
      .filter(hasUpperCase)
      .map(dep => dep.split(path.sep).pop())
      .filter(dep => !!dep); // remove null and empty string
    componentInfo.dependency = dependency;
  } catch (err) {
    console.error(err);
  }
  if (componentInfo) {
    // create new line
    componentInfo.description = componentInfo.description.split(/[\r\n]+/)

    for (let key in componentInfo.props) {
      const prop = componentInfo.props[key];

      // flatten propTypes
      while (
        prop.type &&
        prop.type.value &&
        prop.type.value.value &&
        prop.type.value.name
        // because some prop named 'value', so we need to distinguish the reserved word(value)
        // and word 'value'
      ) {
        if (prop.type.value.name === 'shape') {
          // transform 'shape'
          for (let key in prop.type.value.value) {
            prop.type.value.value[key].value = `${key} : ${prop.type.value.value[key].name}`;
          }
        }
        prop.type.name += ` ${prop.type.value.name}`;
        prop.type.value = prop.type.value.value;
        prop.type.type = prop.type.value.type;
      }

      // make camel case human-readable
      if (prop.type && prop.type.name) {
        prop.type.name = decamelize(prop.type.name, ' ');
      }

      if (prop.description && prop.description.indexOf('@link') !== -1) {
        const tokens = prop.description.split(/[\n\r\s]+/);
        // detect @link
        const href = tokens[tokens.indexOf('@link') + 1];
        // remove @link
        prop.description = prop.description.replace(/@link[\s]+.*[\n\r\s]+/g, '')
        prop.type.link = {
          href,
        };
      }
    }
  }
  return componentInfo;
}
Ejemplo n.º 2
0
 dependencies() {
     return detective(fs.readFileSync(this.location, 'utf8'));
 }
var extract = function(ast) {
	return detective(ast);
};
Ejemplo n.º 4
0
function detectiveEs6Cjs(ast, detectiveOptions) {
  return detectiveEs6(ast, detectiveOptions).concat(detectiveCjs(ast, detectiveOptions));
}