Created
May 25, 2017 00:31
-
-
Save stepancar/78c0911e01bd948ced04d54e1cc7a86c to your computer and use it in GitHub Desktop.
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
function getDtsContent(doc) { | |
console.log(doc.props) | |
return (` | |
import { Component } from 'react'; | |
${doc.composes.map(({ componentName, filePath }) => | |
`import { ${componentName}Props } from './${path.relative(path.dirname(doc.filePath), filePath )}'` | |
)} | |
export interface ${doc.componentName}Props ${doc.composes.length > 0? `extends ${doc.composes.map(({componentName}) => `${componentName}Props`).join(' & ')}`: ''}{ | |
${Object.keys(doc.props).map(propName => { | |
const { required, type } = doc.props[propName]; | |
return `${propName}${required? '': '?'}: ${type.name}`; | |
})} | |
} | |
export default class ${doc.componentName} extends React.Component<${doc.componentName}Props, any>{ | |
${doc.methods.map(({ name, docblock, params, description }) => | |
`${name}(${params.map(({ name }) => | |
`${name}: any`).join(', ') | |
}): any;` | |
)} | |
} | |
`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment