Commit 4289e767 authored by Qiu Xiang's avatar Qiu Xiang

添加文档生成脚本

parent f6bdba71
......@@ -14,8 +14,14 @@
"type": "git",
"url": "https://github.com/qiuxiang/react-native-amap3d"
},
"scripts": {
"docgen": "react-docgen components 2>/dev/null | node scripts/docgen.js"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"devDependencies": {
"react-docgen": "^2.16.0"
}
}
const stdin = process.openStdin()
let data = ''
stdin.on('data', chunk => data += chunk)
stdin.on('end', () => docgen(JSON.parse(data)))
function docgen(docs) {
const components = [
'MapView',
'Marker',
'Polyline',
'Polygon',
'Circle',
]
let markdown = ''
components.forEach(componentName => {
const doc = docs[`components/${componentName}.js`]
markdown += `## ${componentName}\n`
markdown += '### Props\n'
for (let propName in doc.props) {
const prop = doc.props[propName]
const type = formatPropName(prop)
markdown += `#### ${propName}: ${type} ${prop.required ? '`required`' : ''} ${prop.description}\n`
}
markdown += '\n'
})
console.log(markdown)
}
function formatPropName(prop) {
let type = propNameFromCustomType(prop.type)
if (type.indexOf('isRequired') !== -1) {
type = type.replace('.isRequired', '')
prop.required = true
}
if (type === 'arrayOf') {
type += `(${propNameFromCustomType(prop.type.value)})`
}
return type
}
function propNameFromCustomType(type) {
return type.raw || type.name
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment