-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from OriR/improve-extensibility
Improve extensibility
- Loading branch information
Showing
16 changed files
with
3,082 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
coverage: true, | ||
threshold: 100, | ||
globals: '__core-js_shared__', | ||
shuffle: true | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodejs 10.15.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
const os = require('os'); | ||
const { template, type } = require('react-docgen-renderer-template'); | ||
|
||
const generatePropsTable = (props, getType) => { | ||
const entries = Object.entries(props); | ||
if (entries.length === 0) return 'This component does not have any props.'; | ||
|
||
let propsTableHeader = `prop | type | default | required | description | ||
---- | :----: | :-------: | :--------: | ----------- | ||
`; | ||
return propsTableHeader + entries.map(([propName, propValue]) => `**${propName}** | \`${getType(propValue.type)}\` | ${propValue.defaultValue ? `\`${propValue.defaultValue}\`` : '' } | ${propValue.required ? ':white_check_mark:' : ':x:' } | ${propValue.description ? propValue.description : ''}`).join(os.EOL); | ||
}; | ||
|
||
const templateCreator = template({ | ||
unknown: 'Unknown', | ||
func: 'Function', | ||
array: 'Array', | ||
object: 'Object', | ||
string: 'String', | ||
number: 'Number', | ||
bool: 'Boolean', | ||
node: 'ReactNode', | ||
element: 'ReactElement', | ||
symbol: 'Symbol', | ||
any: '*', | ||
custom: '(custom validator)', | ||
shape: 'Shape', | ||
arrayOf: type`Array[]<${({ context, getType }) => getType(context.type.value) }>`, | ||
objectOf: type`Object[#]<${({ context, getType }) => getType(context.type.value) }>`, | ||
instanceOf: type`${({ context }) => context.type.value}`, | ||
enum: type`Enum(${({ context, getType }) => context.type.value.map(value => getType(value)).join(', ')})`, | ||
union: type`Union<${({ context, getType }) => context.type.value.map(value => getType(value)).join('\\|')}>` | ||
}); | ||
|
||
const templateObject = templateCreator`## ${({ context }) => context.componentName}${({ context }) => { | ||
let headerValue = ''; | ||
if (context.srcLinkUrl) { | ||
headerValue = `${os.EOL}From [\`${context.srcLink}\`](${context.srcLinkUrl})`; | ||
} | ||
if (context.description) { | ||
headerValue += os.EOL + os.EOL + context.description; | ||
} | ||
headerValue += os.EOL; | ||
return headerValue; | ||
}} | ||
${({ context, getType }) => generatePropsTable(context.props, getType)} | ||
${({ context }) => context.isMissingComposes | ||
? `*Some or all of the composed components are missing from the list below because a documentation couldn't be generated for them. | ||
See the source code of the component for more information.*` | ||
: ''}${({ context, getType }) => context.composes.length > 0 | ||
? ` | ||
${context.componentName} gets more \`propTypes\` from these composed components | ||
${context.composes.map(component => | ||
`#### ${component.componentName} | ||
${generatePropsTable(component.props, getType)}` | ||
).join(os.EOL + os.EOL)}` | ||
: '' } | ||
`; | ||
|
||
module.exports = templateObject; |
Oops, something went wrong.