-
Notifications
You must be signed in to change notification settings - Fork 255
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 #4 from pvasek/fix/not_exported_props_fails
If props are not exported generation fails - fixed #3
- Loading branch information
Showing
8 changed files
with
196 additions
and
25 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,32 @@ | ||
import * as React from 'react'; | ||
/** | ||
* Column properties. | ||
*/ | ||
interface IColumnProps extends React.HTMLAttributes<any> { | ||
/** prop1 description */ | ||
prop1?: string; | ||
/** prop2 description */ | ||
prop2: number; | ||
/** | ||
* prop3 description | ||
*/ | ||
prop3: () => void; | ||
/** prop4 description */ | ||
prop4: 'option1' | 'option2' | "option3"; | ||
} | ||
|
||
/** | ||
* Form column. | ||
*/ | ||
export class Column extends React.Component<IColumnProps, {}> { | ||
public static defaultProps: Partial<IColumnProps> = { | ||
prop1: 'prop1' | ||
}; | ||
|
||
render() { | ||
const {prop1} = this.props; | ||
return <div>{prop1}</div>; | ||
} | ||
} | ||
|
||
export default Column; |
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,102 @@ | ||
import { assert } from 'chai'; | ||
import * as path from 'path'; | ||
import { getDocumentation } from '../parser'; | ||
import { convertToDocgen, StyleguidistComponent } from "../docgenConverter"; | ||
|
||
describe('docgenConverter', () => { | ||
it('Should work with class Component', () => { | ||
const result = convertToDocgen({ | ||
classes: [ | ||
{ | ||
name: 'name1', | ||
comment: 'comment1', | ||
extends: 'Component', | ||
propInterface: 'PropsInterface', | ||
} | ||
], | ||
interfaces: [ | ||
{ | ||
name: 'PropsInterface', | ||
comment: 'props comment', | ||
members: [ | ||
{ | ||
name: 'prop1', | ||
comment: 'prop1 comment', | ||
isRequired: true, | ||
text: 'prop1 text', | ||
type: 'prop1 type' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
|
||
assert.equal('name1', result.displayName); | ||
assert.equal('comment1', result.description); | ||
const prop1Result = result.props['prop1']; | ||
assert.equal('prop1 type', prop1Result.type.name); | ||
assert.equal('prop1 comment', prop1Result.description); | ||
assert.equal(true, prop1Result.required); | ||
}); | ||
|
||
it('Should work with functional StatelessComponent', () => { | ||
const result = convertToDocgen({ | ||
classes: [ | ||
{ | ||
name: 'name1', | ||
comment: 'comment1', | ||
extends: 'StatelessComponent', | ||
propInterface: 'PropsInterface', | ||
} | ||
], | ||
interfaces: [ | ||
{ | ||
name: 'PropsInterface', | ||
comment: 'props comment', | ||
members: [ | ||
{ | ||
name: 'prop1', | ||
comment: 'prop1 comment', | ||
isRequired: true, | ||
text: 'prop1 text', | ||
type: 'prop1 type' | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
|
||
assert.equal('name1', result.displayName); | ||
assert.equal('comment1', result.description); | ||
const prop1Result = result.props['prop1']; | ||
assert.equal('prop1 type', prop1Result.type.name); | ||
assert.equal('prop1 comment', prop1Result.description); | ||
assert.equal(true, prop1Result.required); | ||
}); | ||
|
||
it('Should work without props interface', () => { | ||
let result: StyleguidistComponent = null; | ||
const originalWarn = console.warn; | ||
let warnCallCount = 0; | ||
console.warn = () => warnCallCount++; | ||
try { | ||
result = convertToDocgen({ | ||
classes: [ | ||
{ | ||
name: 'name1', | ||
comment: 'comment1', | ||
extends: 'Component', | ||
propInterface: null, | ||
} | ||
], | ||
interfaces: [] | ||
}); | ||
} finally { | ||
console.warn = originalWarn; | ||
} | ||
|
||
assert.equal(1, warnCallCount); | ||
assert.equal('name1', result.displayName); | ||
assert.equal('comment1', result.description); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import { parse } from './propTypesParser'; | ||
import { StyleguidistComponent, StyleguidistProps } from './docgenConverter'; | ||
|
||
export { | ||
parse, | ||
StyleguidistComponent, | ||
StyleguidistProps, | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { getDocumentation } from './parser'; | ||
import { convertToDocgen } from './docgenConverter'; | ||
import { convertToDocgen, StyleguidistComponent } from './docgenConverter'; | ||
|
||
/** | ||
* Parser given file and return documentation in format compatibe with react-docgen. | ||
*/ | ||
export function parse(filePath: string) { | ||
export function parse(filePath: string): StyleguidistComponent { | ||
const doc = getDocumentation(filePath); | ||
return convertToDocgen(doc); | ||
} |