diff --git a/core/specification/README.md b/core/specification/README.md index 22dcc28f7..6dea40767 100644 --- a/core/specification/README.md +++ b/core/specification/README.md @@ -3,7 +3,7 @@ - [Overview](#overview) - [Installation](#installation) - [API](#api) - - [run](#run) + - [RectDocgenTypescriptOptions](#rectdocgentypescriptoptions) # Overview @@ -23,19 +23,17 @@ $ npm install @component-controls/specification --save-dev -## run +## RectDocgenTypescriptOptions -run API to generate react-docgen-typescript props information tables. +a callback to transfor them props table and the options to be passd to react-docgen-typescript. _defined in [@component-controls/specification/src/test.ts](https://github.com/ccontrols/component-controls/tree/master/core/specification/src/test.ts#L6)_ -**run**(`options`: undefined | string): number; +### properties -### parameters - -| Name | Type | Description | -| --------- | ------------------- | ------------------------------------------------------- | -| `options` | undefined \| string | configuration options | -| `returns` | number | a callable function of type PropsInfoExtractorFunction | +| Name | Type | Description | +| ---------------- | ------------------------------------------------------------------------------------------ | ------------------------------------- | +| `transformProps` | undefined \| (`props`\*: [ComponentDoc](#componentdoc)\[]): [ComponentDoc](#componentdoc); | callback to transform the props table | +| `ParserOptions` | [ParserOptions](#parseroptions) | | diff --git a/core/specification/src/test.ts b/core/specification/src/test.ts index 5e5cc0526..783040b83 100644 --- a/core/specification/src/test.ts +++ b/core/specification/src/test.ts @@ -1,8 +1,11 @@ +import { ParserOptions, ComponentDoc } from 'react-docgen-typescript'; + /** - * run API to generate react-docgen-typescript props information tables. - * @param options configuration options - * @returns a callable function of type PropsInfoExtractorFunction + * a callback to transfor them props table and the options to be passd to react-docgen-typescript. */ -export const run = (options?: string): number => { - return parseInt(options || ''); -}; +export type RectDocgenTypescriptOptions = { + /** + * callback to transform the props table + */ + transformProps?: (props: ComponentDoc[]) => ComponentDoc; +} & ParserOptions; diff --git a/core/specification/tmp-out-typedoc.json b/core/specification/tmp-out-typedoc.json index cad59c711..7f4f286c6 100644 --- a/core/specification/tmp-out-typedoc.json +++ b/core/specification/tmp-out-typedoc.json @@ -17,77 +17,141 @@ "children": [ { "id": 2, - "name": "run", - "kind": 64, - "kindString": "Function", + "name": "RectDocgenTypescriptOptions", + "kind": 4194304, + "kindString": "Type alias", "flags": { - "isExported": true, - "isConst": true + "isExported": true }, "comment": { - "shortText": "run API to generate react-docgen-typescript props information tables.", - "returns": "a callable function of type PropsInfoExtractorFunction\n" + "shortText": "a callback to transfor them props table and the options to be passd to react-docgen-typescript." }, - "signatures": [ + "sources": [ { - "id": 3, - "name": "run", - "kind": 4096, - "kindString": "Call signature", - "flags": { - "isExported": true - }, - "comment": { - "shortText": "run API to generate react-docgen-typescript props information tables.", - "returns": "a callable function of type PropsInfoExtractorFunction\n" - }, - "parameters": [ - { - "id": 4, - "name": "options", - "kind": 32768, - "kindString": "Parameter", + "fileName": "test.ts", + "line": 6, + "character": 39 + } + ], + "type": { + "type": "intersection", + "types": [ + { + "type": "reflection", + "declaration": { + "id": 3, + "name": "__type", + "kind": 65536, + "kindString": "Type literal", "flags": { - "isExported": true, - "isOptional": true + "isExported": true }, - "comment": { - "shortText": "configuration options" - }, - "type": { - "type": "union", - "types": [ - { - "type": "intrinsic", - "name": "undefined" + "children": [ + { + "id": 4, + "name": "transformProps", + "kind": 32, + "kindString": "Variable", + "flags": { + "isExported": true, + "isOptional": true + }, + "comment": { + "shortText": "callback to transform the props table" }, - { - "type": "intrinsic", - "name": "string" + "sources": [ + { + "fileName": "test.ts", + "line": 10, + "character": 16 + } + ], + "type": { + "type": "union", + "types": [ + { + "type": "intrinsic", + "name": "undefined" + }, + { + "type": "reflection", + "declaration": { + "id": 5, + "name": "__type", + "kind": 65536, + "kindString": "Type literal", + "flags": { + "isExported": true + }, + "signatures": [ + { + "id": 6, + "name": "__call", + "kind": 4096, + "kindString": "Call signature", + "flags": { + "isExported": true + }, + "parameters": [ + { + "id": 7, + "name": "props", + "kind": 32768, + "kindString": "Parameter", + "flags": { + "isExported": true + }, + "type": { + "type": "array", + "elementType": { + "type": "reference", + "name": "ComponentDoc" + } + } + } + ], + "type": { + "type": "reference", + "name": "ComponentDoc" + } + } + ] + } + } + ] } - ] - } + } + ], + "groups": [ + { + "title": "Variables", + "kind": 32, + "children": [ + 4 + ] + } + ], + "sources": [ + { + "fileName": "test.ts", + "line": 6, + "character": 41 + } + ] } - ], - "type": { - "type": "intrinsic", - "name": "number" + }, + { + "type": "reference", + "name": "ParserOptions" } - } - ], - "sources": [ - { - "fileName": "test.ts", - "line": 6, - "character": 16 - } - ] + ] + } } ], "groups": [ { - "title": "Functions", - "kind": 64, + "title": "Type aliases", + "kind": 4194304, "children": [ 2 ] diff --git a/props-info/react-docgen-typescript/README.md b/props-info/react-docgen-typescript/README.md index 05f80cfba..c1334d314 100644 --- a/props-info/react-docgen-typescript/README.md +++ b/props-info/react-docgen-typescript/README.md @@ -49,9 +49,10 @@ _defined in [@component-controls/react-docgen-typescript-info/src/index.ts](http ### parameters -| Name | Type | Description | -| --------- | ----------------------------------------------------------- | --------------------- | -| `options` | [RectDocgenTypescriptOptions](#rectdocgentypescriptoptions) | configuration options | +| Name | Type | Description | +| --------- | ----------------------------------------------------------- | ------------------------------------------------------- | +| `options` | [RectDocgenTypescriptOptions](#rectdocgentypescriptoptions) | configuration options | +| `returns` | [PropsInfoExtractorFunction](#propsinfoextractorfunction) | a callable function of type PropsInfoExtractorFunction | ## RectDocgenTypescriptOptions @@ -59,15 +60,12 @@ a callback to transfor them props table and the options to be passd to react-doc _defined in [@component-controls/react-docgen-typescript-info/src/types.ts](https://github.com/ccontrols/component-controls/tree/master/props-info/react-docgen-typescript/src/types.ts#L6)_ -**properties:** - -callback to transform the props table - -**transformProps**: undefined | (`props`\*: [ComponentDoc](#componentdoc)\[]): [ComponentDoc](#componentdoc); - -[ParserOptions](#parseroptions) +### properties --- +| Name | Type | Description | +| ---------------- | ------------------------------------------------------------------------------------------ | ------------------------------------- | +| `transformProps` | undefined \| (`props`\*: [ComponentDoc](#componentdoc)\[]): [ComponentDoc](#componentdoc); | callback to transform the props table | +| `ParserOptions` | [ParserOptions](#parseroptions) | | ## ComponentDoc @@ -130,10 +128,11 @@ _defined in [react-docgen-typescript/lib/parser.d.ts](https://github.com/stylegu ### parameters -| Name | Type | Description | -| --------- | ------------------------- | ----------- | -| `exp*` | [Symbol](#symbol) | | -| `source*` | [SourceFile](#sourcefile) | | +| Name | Type | Description | +| --------- | ------------------------------------ | ----------- | +| `exp*` | [Symbol](#symbol) | | +| `source*` | [SourceFile](#sourcefile) | | +| `returns` | string \| undefined \| null \| false | | ## StaticPropFilter @@ -160,6 +159,7 @@ _defined in [react-docgen-typescript/lib/parser.d.ts](https://github.com/stylegu | ------------ | ----------------------- | ----------- | | `props*` | [PropItem](#propitem) | | | `component*` | [Component](#component) | | +| `returns` | boolean | | ## MethodParameter diff --git a/scripts/tsdoc/extract-tsdoc.ts b/scripts/tsdoc/extract-tsdoc.ts index feb846f34..e49c0b3ef 100644 --- a/scripts/tsdoc/extract-tsdoc.ts +++ b/scripts/tsdoc/extract-tsdoc.ts @@ -66,13 +66,22 @@ export const extractTSDoc = (files: string[], entries: string[]): Node[] | undef children: [table] }); nodes.forEach((child: any) => { - const tableRow: NodeChildren = createPropsRpw( - child.name, - child.flags.isOptional, - child.type ? extractPropType(child.type) : extractFunction(child, false), - child.comment ? child.comment.shortText : ''); - //@ts-ignore - table.children.push(tableRow); + if (child.declaration) { + //@ts-ignore + table.children.push.apply(table.children, child.declaration.children.map((d: any) => createPropsRpw( + d.name, + d.flags ? d.flags.isOptional : true, + d.type ? extractPropType(d.type) : extractFunction(d, false), + d.comment ? d.comment.shortText : ''))); + } else { + const tableRow: NodeChildren = createPropsRpw( + child.name, + child.flags ? child.flags.isOptional : true, + child.type ? extractPropType(child.type.type ? child.type: child) : extractFunction(child, false), + child.comment ? child.comment.shortText : ''); + //@ts-ignore + table.children.push(tableRow); + } }); } return { propsTable, table }; @@ -97,7 +106,7 @@ export const extractTSDoc = (files: string[], entries: string[]): Node[] | undef }] }); } - const signature = node.signatures.find((s: any) => s.kindString === 'Call signature'); + const signature = node.signatures && node.signatures.find((s: any) => s.kindString === 'Call signature'); if (signature) { declaration.children.push({ type: 'text', @@ -320,28 +329,8 @@ export const extractTSDoc = (files: string[], entries: string[]): Node[] | undef }, []); } case 'intersection': { - return [ - { - type: 'strong', - children: [ - { - type: 'text', - value: 'properties:', - } - ] - }, - ...p.types.reduce((acc: any, t: any, idx: number) => { - const props = extractPropType(t); - return [...acc, - ...props - ]; - }, []), - { - type: 'text', - value: '--' - }, - - ]; + const { propsTable } = extractPropTable(p.types, 'properties'); + return propsTable; } case 'array': { return [{ @@ -436,16 +425,13 @@ export const extractTSDoc = (files: string[], entries: string[]): Node[] | undef switch (node.kindString) { case 'Type alias': - case 'Type literal': { - if (node.type) { - result.push.apply(result, extractPropType(node.type, true)); - } else { + result.push.apply(result, extractPropType(node.type, true)); + break; + case 'Type literal': node.children.forEach((child: any) => { result.push.apply(result, extractPropType(child, true)); }) - } break; - } case 'Class': case 'Interface': default: {