(config, file, directory)
| 69 | } |
| 70 | |
| 71 | function generateComponentData(config, file, directory) { |
| 72 | const filePath = path.join(directory, file); |
| 73 | |
| 74 | try { |
| 75 | const docgen = getDocgen(config, filePath); |
| 76 | |
| 77 | const doc = { |
| 78 | ...docgen, |
| 79 | propsDefinition: objectToString(docgen.props) |
| 80 | } |
| 81 | |
| 82 | const normalizedFile = normalizePath(file); |
| 83 | const menu = normalizedFile |
| 84 | .replace(/\.\.\//g, '') |
| 85 | .replace('.react', '') |
| 86 | .replace(/\.(js|jsx|tsx)$/, '') |
| 87 | .replace(/(?:^|\/)(\w)/g, (_, c) => c ? ` ${c.toUpperCase()}` : '') |
| 88 | .replace(/(?:^|[-_])(\w)/g, (_, c) => c ? `${c.toUpperCase()}` : '') |
| 89 | .replace(/\//g, '') |
| 90 | .trim(); |
| 91 | |
| 92 | |
| 93 | const name = menu.replace(/\W/g, ''); |
| 94 | |
| 95 | const importFile = normalizePath(getImportFile(directory, file)); |
| 96 | const componentName = normalizedFile.replace(/.*\//, '').split('.')[0]; |
| 97 | const simpleProps = objectToString(buildProps(docgen.props)) |
| 98 | const fullProps = objectToString(buildProps(docgen.props, true)) |
| 99 | |
| 100 | return { |
| 101 | file: importFile, |
| 102 | componentName, |
| 103 | menu, |
| 104 | name, |
| 105 | simpleProps, |
| 106 | fullProps, |
| 107 | ...doc, |
| 108 | }; |
| 109 | } |
| 110 | catch (error) { |
| 111 | if (error.message !== 'No suitable component definition found.') |
| 112 | console.error(`\u001b[31mError parsing component ${file}: ${error.message}\u001b[0m`, error.stack) // eslint-disable-line no-console |
| 113 | else |
| 114 | console.warn(`\u001b[33m No suitable component definition found in ${file}\u001b[0m`) // eslint-disable-line no-console |
| 115 | return null; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | function getValidFiles(files) { |
| 120 | return [].concat.apply([], files).filter(file => !!file); |
no test coverage detected