Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(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`;
}
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))}
})
`
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)
}
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) {