Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-docgen-typescript",
"version": "0.0.13",
"version": "0.0.14",
"description": "",
"main": "lib/index.js",
"scripts": {
Expand Down
14 changes: 10 additions & 4 deletions src/__tests__/docgenConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StyleguidistComponent } from '../propTypesParser';

describe('docgenConverter', () => {
it('Should work with class Component', () => {
const result = convertToDocgen({
const result = convertToDocgen('', {
components: [
{
name: 'name1',
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('docgenConverter', () => {
});

it('Should work with functional StatelessComponent', () => {
const result = convertToDocgen({
const result = convertToDocgen('', {
components: [
{
name: 'name1',
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('docgenConverter', () => {
let warnCallCount = 0;
console.warn = () => warnCallCount++;
try {
result = convertToDocgen({
result = convertToDocgen('', {
components: [
{
name: 'name1',
Expand All @@ -91,7 +91,7 @@ describe('docgenConverter', () => {
let warnCallCount = 0;
console.warn = () => warnCallCount++;
try {
result = convertToDocgen({
result = convertToDocgen('', {
components: [
{
name: 'name1',
Expand All @@ -109,4 +109,10 @@ describe('docgenConverter', () => {
assert.equal('name1', result.displayName);
assert.equal('comment1', result.description);
});

it('Should return empty object if there are no components', () => {
const result = convertToDocgen('/root/MyComponent.tsx', { components: [] });
assert.isOk(result);
assert.equal(result.displayName, 'MyComponent');
})
});
9 changes: 7 additions & 2 deletions src/docgenConverter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import * as path from 'path';
import { FileDoc, InterfaceDoc, MemberDoc } from './model';
import { StyleguidistComponent, StyleguidistProps, PropItem } from './propTypesParser';

export function convertToDocgen(doc: FileDoc): StyleguidistComponent | null {
export function convertToDocgen(filePath: string, doc: FileDoc): StyleguidistComponent {
const components = doc.components;

if (components.length === 0) {
return null;
return {
displayName: path.basename(filePath, path.extname(filePath)),
description: '',
props: {},
};
}
const comp = components[0];

Expand Down
2 changes: 1 addition & 1 deletion src/propTypesParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export interface PropItemType {
*/
export function parse(filePath: string): StyleguidistComponent {
const doc = getFileDocumentation(filePath);
return convertToDocgen(doc);
return convertToDocgen(filePath, doc);
}