Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.map(path => {
try {
/* ignore secondary files */
const directoryName = path.split('/').splice(-2, 1)[0]
const componentFileName = directoryName.replace('_', '') + '.js'
/* if component file does not exist, move on*/
if (!path.includes(componentFileName)) return
/* append display name handler to handlers list */
const handlers = docgen.defaultHandlers
.concat(createDisplayNameHandler(path))
.concat(deprecationHandler)
/* read file to get source code */
const code = fs.readFileSync(path, 'utf8')
/* parse the component code to get metadata */
const data = docgen.parse(code, null, handlers)
/* make modifications to prop types to improve documentation */
if (data.props) {
Object.values(data.props).forEach(prop => {
/* remove redundant quotes from default value of type string */
if (prop.defaultValue) {
if (typeof prop.defaultValue.value === 'string') {
prop.defaultValue.value = prop.defaultValue.value.replace(/^'(.*)'$/, '$1')
astPath.get('properties').value
),
null, // TypeAnnotation
true // static
)]
)
);
astPath.replace(FauxView);
}
return docgen.parse(
fs.readFileSync(docsList.viewPropTypes),
viewPropTypesResolver,
[
viewPropTypesConversionHandler,
...docgen.defaultHandlers,
]
);
}
astPath.get('properties').value
),
null, // TypeAnnotation
true // static
)]
)
);
astPath.replace(FauxView);
}
return docgen.parse(
fs.readFileSync(docsList.viewPropTypes),
viewPropTypesResolver,
[
viewPropTypesConversionHandler,
].concat(docgen.defaultHandlers)
);
}
const startTime = process.hrtime();
/**
* External Dependencies
*/
require( 'babel-register' );
const fs = require( 'fs' );
const path = require( 'path' );
const reactDocgen = require( 'react-docgen' );
const { getPropertyName, getMemberValuePath, resolveToValue } = require( 'react-docgen/dist/utils' );
const util = require( 'client/devdocs/docs-example/util' );
const globby = require( 'globby' );
const root = path.dirname( path.join( __dirname, '..', '..' ) );
const handlers = [ ...reactDocgen.defaultHandlers, commentHandler ];
/**
* Replaces **'s in comment blocks and trims comments
* @param {string} str The doc string to clean
*/
function parseDocblock( str ) {
const lines = str.split( '\n' );
for ( let i = 0, l = lines.length; i < l; i++ ) {
lines[ i ] = lines[ i ].replace( /^\s*\*\s?/, '' );
}
return lines.join( '\n' ).trim();
}
/**
* Given a path, this function returns the closest preceding comment, if it exists
* @param {NodePath} path The node path from react-docgen
const jsParser = async (filepath: string, config: Config) => {
const resolver =
config.docgenConfig.resolver ||
reactDocgen.resolver.findAllExportedComponentDefinitions
const handlers = reactDocgen.defaultHandlers.concat([
externalProptypesHandler(filepath),
actualNameHandler,
])
try {
const code = fs.readFileSync(filepath, 'utf-8')
const data = reactDocgen.parse(code, resolver, handlers)
return { [filepath]: data }
} catch (err) {
if (config.debug) throwError(err)
return null
}
}
function renderComponent(filepath) {
const json = docgen.parse(
fs.readFileSync(filepath),
docgenHelpers.findExportedOrFirst,
docgen.defaultHandlers.concat([
docgenHelpers.stylePropTypeHandler,
docgenHelpers.deprecatedPropTypeHandler,
])
);
return componentsToMarkdown('component', json, filepath, componentCount++, styleDocs);
}
const parseFilepathProps = (filepath: string) => {
const fullpath = path.resolve(root, filepath)
const handlers = reactDocgen.defaultHandlers.concat([
externalProptypesHandler(filepath),
actualNameHandler,
])
try {
const code = fs.readFileSync(fullpath, { encoding: 'utf-8' })
const props = reactDocgen.parse(code, resolver, handlers)
return { key: unixPath(filepath), value: props }
} catch (err) {
if (config.debug) throwError(err)
return null
}
}
const defaultHandlers = require('react-docgen').defaultHandlers;
const markdownHandler = require('./markdownHandler');
/**
* Add our custom handlers to react-docgen's default list of handlers
* @param {String} rootPath - Root docs site path
* @return {Array}
*/
module.exports = rootPath => {
return defaultHandlers.concat([markdownHandler(rootPath)]);
};
function extractSource(source, options = {}) {
const { filePath, componentName } = options;
let componentInfo;
try {
componentInfo = reactDocs.parse(
source,
reactDocs.resolver.findExportedComponentDefinition,
reactDocs.defaultHandlers
);
} catch (e) {
if (e.message !== 'No suitable component definition found.') {
e.message = `${e.message}\n[${filePath}]`;
throw e;
}
}
if (componentInfo) {
return filter(componentInfo, options);
}
return null;
}
handlers: componentPath => {
require('react-docgen').defaultHandlers.concat(
require('react-docgen-displayname-handler').createDisplayNameHandler(
componentPath
)
)
},
webpackConfig: {