How to use the react-docgen.resolver.findAllExportedComponentDefinitions function in react-docgen

To help you get started, we’ve selected a few react-docgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marborkowski / react-doc-generator / src / react-doc-generator.js View on Github external
(err, content, filename, next) => {
            if (err) {
                throw err;
            }

            try {
                let components = parse(content, resolver.findAllExportedComponentDefinitions);
                components = components.map(component => {
                    if (component.description && !component.displayName) {
                        component.title = component.description.match(/^(.*)$/m)[0];
                        if (component.description.split('\n').length > 1) {
                            component.description = component.description.replace(/[\w\W]+?\n+?/, '');
                            component.description = component.description.replace(/(\n)/gm, '   \n');
                        } else {
                            component.description = null;
                        }
                    } else {
                        component.title = component.displayName;
                    }

                    if (component.description) {
                        component.description = `${component.description}   \n\n`;
                    }
github instructure / instructure-ui / packages / generate-examples / src / examples-loader.js View on Github external
const basePath = path.dirname(configPath)

        const examplesConfigPath = config.configPath ? path.resolve(basePath, config.configPath) : null
        const componentPath = path.resolve(basePath, config.componentPath || (function () {
          const fallback = 'index.js'
          loader.emitWarning(
            new Error(`Expected property 'componentPath' was not supplied in configuration file at '${basePath}' Attempting to use ${fallback} instead.`)
          )
          return fallback
        }()))

        let parsedSrc
        try {
          parsedSrc = parse(
            fs.readFileSync(`${componentPath}${!componentPath.includes('.') ? '.js' : ''}`, 'utf8'),
            resolver.findAllExportedComponentDefinitions
          )
          if (Array.isArray(parsedSrc)) {
            parsedSrc = parsedSrc.pop()
          }
        } catch (error) {
          loader.emitWarning(error)
        }

        return `
          examples.push({
            displayName: '${config.name || parseExampleNameFromPath(componentPath)}',
            ${examplesConfigPath ? `config: require('${examplesConfigPath}').default,` : ''}
            component: require('${componentPath}').default,
            props: ${JSON.stringify(parsePropsFromSource(parsedSrc))}
          })
        `
github instructure / instructure-ui / packages / ui-component-examples / src / parsePropValues.js View on Github external
export default function parsePropValues (fileSource) {
  let parsedSrc = {}
  try {
    parsedSrc = parse(
     fileSource,
     resolver.findAllExportedComponentDefinitions
    )
    if (Array.isArray(parsedSrc)) {
      parsedSrc = parsedSrc.pop()
    }
  } catch (error) {
    throw new Error(
      `[ui-component-examples] Could not parse component source: ${error}`
    )
  }

  return getPropValuesFromParsedProps(parsedSrc.props)
}
github propertybase / react-lds / docs / src / app / components / PropTypeDescription / index.js View on Github external
const PropTypeDescription = ({ code, header }) => {
  let requiredProps = 0;

  let text = `${header}
| Name | Type | Default | Description |
|:-----|:-----|:-----|:-----|\n`;

  const componentInfo = parse(code, resolver.findAllExportedComponentDefinitions);

  const firstComponent = componentInfo['0'];

  if (firstComponent.props) {
    Object.keys(firstComponent.props).forEach((key) => {
      if ({}.hasOwnProperty.call(firstComponent.props, key)) {
        let workingKey = key;
        const prop = firstComponent.props[workingKey];

        const description = generateDescription(prop.required, prop.description, prop.type);

        if (description === null) return;

        let defaultValue = '';

        if (prop.defaultValue) {