Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(utils): replace react-docgen with typescript #460

Merged
merged 15 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 0 additions & 162 deletions build/gulp/plugins/util/findExportedComponentDefinitions.ts

This file was deleted.

21 changes: 4 additions & 17 deletions build/gulp/plugins/util/getComponentInfo.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import * as _ from 'lodash'
import * as path from 'path'
import { defaultHandlers, parse } from 'react-docgen'
import * as fs from 'fs'
import * as ts from 'typescript'
import parseDefaultValue from './parseDefaultValue'
import parseDocblock from './parseDocblock'
import parserCustomHandler from './parserCustomHandler'
import parseType from './parseType'
import findExportedComponentDefinitions from './findExportedComponentDefinitions'
import * as reactDocgenTypescript from 'react-docgen-typescript'

const getComponentInfo = filepath => {
const absPath = path.resolve(process.cwd(), filepath)

const contents = fs.readFileSync(absPath).toString()
const dir = path.dirname(absPath)
const dirname = path.basename(dir)
const filename = path.basename(absPath)
Expand All @@ -22,18 +18,9 @@ const getComponentInfo = filepath => {
// "element" for "src/elements/Button/Button.js"
const componentType = path.basename(path.dirname(dir)).replace(/s$/, '')

const text = ts.transpile(contents, {
jsx: ts.JsxEmit.React,
target: ts.ScriptTarget.Latest,
module: ts.ModuleKind.CommonJS,
allowSyntheticDefaultImports: true,
})
// start with react-docgen-typescript info
const components = reactDocgenTypescript.withDefaultConfig().parse(absPath)

// start with react-docgen info
const components = parse(text, findExportedComponentDefinitions, [
...defaultHandlers,
parserCustomHandler,
])
if (!components.length) {
throw new Error(`Could not find a component definition in "${filepath}".`)
}
Expand All @@ -45,7 +32,7 @@ const getComponentInfo = filepath => {
].join(' '),
)
}
const info = components[0]
const info: any = components[0]

// remove keys we don't use
delete info.methods
Expand Down
1 change: 0 additions & 1 deletion build/gulp/plugins/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export { default as getComponentInfo } from './getComponentInfo'
export { default as parseDefaultValue } from './parseDefaultValue'
export { default as parseDocblock } from './parseDocblock'
export { default as parseDocSection } from './parseDocSection'
export { default as parserCustomHandler } from './parserCustomHandler'
export { default as parseType } from './parseType'
50 changes: 0 additions & 50 deletions build/gulp/plugins/util/isUIComponentClass.ts

This file was deleted.

51 changes: 0 additions & 51 deletions build/gulp/plugins/util/parserCustomHandler.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const rowStyle: any = {
flexDirection: 'row',
}

const getTagType = tag => (tag.type.type === 'AllLiteral' ? 'any' : tag.type.name)
const getTagType = tag => (tag.type ? (tag.type.type === 'AllLiteral' ? 'any' : tag.type.name) : '')

const ComponentPropFunctionSignature: any = ({ name, tags }) => {
const params = _.filter(tags, { title: 'param' })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"lodash": "^4.17.10",
"prop-types": "^15.6.1",
"react-custom-scrollbars": "^4.2.1",
"react-docgen-typescript": "^1.12.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this should be in devDependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch! Moved.

"react-fela": "^7.2.0",
"react-popper": "^1.0.2",
"what-input": "^5.1.2"
Expand Down Expand Up @@ -144,7 +145,6 @@
"raw-loader": "^0.5.1",
"react": "^16.0.0",
"react-ace": "^5.1.2",
"react-docgen": "^2.17.0",
"react-document-title": "^2.0.3",
"react-dom": "^16.0.0",
"react-hot-loader": "^4.1.3",
Expand Down
Loading