react-docgen for TypeScript
Summary: Update react-docgen to support TypeScript Reviewed By: passy Differential Revision: D17204178 fbshipit-source-id: 408ce5569a253c9a836f65bd9a9f289cc82b5175
This commit is contained in:
committed by
Facebook Github Bot
parent
eff95991c6
commit
98b4071242
@@ -20,12 +20,12 @@ Flipper has a lot of built in React components to build UIs. You can import them
|
||||
|
||||
const TARGET = __dirname + '/../docs/extending/ui-components.md';
|
||||
|
||||
glob(__dirname + '/../src/ui/components/**/*.js', (err, files) => {
|
||||
glob(__dirname + '/../src/ui/components/**/*.tsx', (err, files) => {
|
||||
const content = files
|
||||
.map(f => [f, fs.readFileSync(f)])
|
||||
.map(([name, file]) => {
|
||||
try {
|
||||
const doc = reactDocs.parse(file);
|
||||
const doc = reactDocs.parse(file, null, null, {filename: name});
|
||||
console.log(`✅ ${name}`);
|
||||
return doc;
|
||||
} catch (e) {
|
||||
@@ -51,7 +51,7 @@ function parseHOC(name, file) {
|
||||
try {
|
||||
const ast = babylon.parse(file.toString(), {
|
||||
sourceType: 'module',
|
||||
plugins: ['flow', 'objectRestSpread', 'classProperties'],
|
||||
plugins: ['typescript', 'objectRestSpread', 'classProperties'],
|
||||
});
|
||||
|
||||
// find the default export from the file
|
||||
@@ -85,20 +85,20 @@ function generateMarkdown(component) {
|
||||
props = '| Property | Type | Description |\n';
|
||||
props += '|---------|------|-------------|\n';
|
||||
Object.keys(component.props).forEach(prop => {
|
||||
let {flowType, description} = component.props[prop];
|
||||
let {tsType, description} = component.props[prop];
|
||||
|
||||
let type = '';
|
||||
if (flowType) {
|
||||
if (flowType.nullable) {
|
||||
if (tsType) {
|
||||
if (tsType.nullable) {
|
||||
type += '?';
|
||||
}
|
||||
|
||||
type +=
|
||||
flowType.name === 'signature' ||
|
||||
flowType.name === 'union' ||
|
||||
flowType.name === 'Array'
|
||||
? flowType.raw
|
||||
: flowType.name;
|
||||
tsType.name === 'signature' ||
|
||||
tsType.name === 'union' ||
|
||||
tsType.name === 'Array'
|
||||
? tsType.raw
|
||||
: tsType.name;
|
||||
}
|
||||
|
||||
// escape pipes and new lines because they will break tables
|
||||
|
||||
Reference in New Issue
Block a user