From 0016449141cef863cc182587063e5326430f0f6f Mon Sep 17 00:00:00 2001 From: "patrick.lafrance" Date: Wed, 13 Nov 2019 11:19:32 -0500 Subject: [PATCH] Renamed lib2 to lib --- addons/docs/src/blocks/Description.tsx | 2 +- addons/docs/src/blocks/Props.tsx | 2 +- addons/docs/src/frameworks/common/index.ts | 2 +- addons/docs/src/frameworks/react/config.ts | 2 +- .../docs/src/frameworks/react/extractProps.ts | 4 +- ...rDefaultValue.ts => createDefaultValue.ts} | 38 ++++++------------- .../{renderType.ts => createType.ts} | 7 +--- .../propTypes/generateFuncSignature.test.ts | 2 +- .../react/propTypes/generateFuncSignature.ts | 2 +- .../frameworks/react/propTypes/handleProp.ts | 10 ++--- addons/docs/src/frameworks/vue/config.tsx | 2 +- .../docs/src/frameworks/vue/extractProps.ts | 4 +- .../docgen/createDefaultValue.ts} | 2 +- .../src/{lib2 => lib}/docgen/createPropDef.ts | 4 +- .../docgen/extractDocgenProps.ts | 0 addons/docs/src/lib/docgen/index.ts | 3 ++ addons/docs/src/{lib2 => lib}/docgen/types.ts | 0 addons/docs/src/{lib2 => lib}/docgen/utils.ts | 0 addons/docs/src/lib/docgenUtils.ts | 13 ------- .../src/{lib2 => lib}/jsdocParser.test.ts | 0 addons/docs/src/{lib2 => lib}/jsdocParser.ts | 0 21 files changed, 35 insertions(+), 64 deletions(-) rename addons/docs/src/frameworks/react/propTypes/{renderDefaultValue.ts => createDefaultValue.ts} (69%) rename addons/docs/src/frameworks/react/propTypes/{renderType.ts => createType.ts} (97%) rename addons/docs/src/{lib2/docgen/renderDefaultValue.ts => lib/docgen/createDefaultValue.ts} (88%) rename addons/docs/src/{lib2 => lib}/docgen/createPropDef.ts (96%) rename addons/docs/src/{lib2 => lib}/docgen/extractDocgenProps.ts (100%) create mode 100644 addons/docs/src/lib/docgen/index.ts rename addons/docs/src/{lib2 => lib}/docgen/types.ts (100%) rename addons/docs/src/{lib2 => lib}/docgen/utils.ts (100%) delete mode 100644 addons/docs/src/lib/docgenUtils.ts rename addons/docs/src/{lib2 => lib}/jsdocParser.test.ts (100%) rename addons/docs/src/{lib2 => lib}/jsdocParser.ts (100%) diff --git a/addons/docs/src/blocks/Description.tsx b/addons/docs/src/blocks/Description.tsx index bf30bc35bf1..c242d4327d8 100644 --- a/addons/docs/src/blocks/Description.tsx +++ b/addons/docs/src/blocks/Description.tsx @@ -2,7 +2,7 @@ import React, { FunctionComponent } from 'react'; import { Description, DescriptionProps as PureDescriptionProps } from '@storybook/components'; import { DocsContext, DocsContextProps } from './DocsContext'; import { Component, CURRENT_SELECTION } from './shared'; -import { str } from '../lib2/docgen/utils'; +import { str } from '../lib/docgen/utils'; export enum DescriptionType { INFO = 'info', diff --git a/addons/docs/src/blocks/Props.tsx b/addons/docs/src/blocks/Props.tsx index 1656af59904..c5794f78c44 100644 --- a/addons/docs/src/blocks/Props.tsx +++ b/addons/docs/src/blocks/Props.tsx @@ -3,7 +3,7 @@ import { PropsTable, PropsTableError, PropsTableProps } from '@storybook/compone import { DocsContext, DocsContextProps } from './DocsContext'; import { Component, CURRENT_SELECTION } from './shared'; -import { PropsExtractor } from '../lib/docgenUtils'; +import { PropsExtractor } from '../lib/docgen/types'; import { extractProps as reactExtractProps } from '../frameworks/react/extractProps'; import { extractProps as vueExtractProps } from '../frameworks/vue/extractProps'; diff --git a/addons/docs/src/frameworks/common/index.ts b/addons/docs/src/frameworks/common/index.ts index 20a01c967ea..3de17860d84 100644 --- a/addons/docs/src/frameworks/common/index.ts +++ b/addons/docs/src/frameworks/common/index.ts @@ -1 +1 @@ -export * from '../../lib/docgenUtils'; +export * from '../../lib/docgen'; diff --git a/addons/docs/src/frameworks/react/config.ts b/addons/docs/src/frameworks/react/config.ts index 0fbcc4c8ade..11c34986a0a 100644 --- a/addons/docs/src/frameworks/react/config.ts +++ b/addons/docs/src/frameworks/react/config.ts @@ -2,7 +2,7 @@ import { addParameters } from '@storybook/client-api'; import { StoryFn } from '@storybook/addons'; import { extractProps } from './extractProps'; -import { extractComponentDescription } from '../../lib2/docgen/utils'; +import { extractComponentDescription } from '../../lib/docgen'; addParameters({ docs: { diff --git a/addons/docs/src/frameworks/react/extractProps.ts b/addons/docs/src/frameworks/react/extractProps.ts index 9462e9673d7..d05f6e27d6e 100644 --- a/addons/docs/src/frameworks/react/extractProps.ts +++ b/addons/docs/src/frameworks/react/extractProps.ts @@ -1,9 +1,7 @@ import PropTypes from 'prop-types'; import { isForwardRef, isMemo } from 'react-is'; import { PropDef } from '@storybook/components'; -import { hasDocgen } from '../../lib2/docgen/utils'; -import { extractPropsFromDocgen } from '../../lib2/docgen/extractDocgenProps'; -import { PropsExtractor, TypeSystem } from '../../lib2/docgen/types'; +import { hasDocgen, extractPropsFromDocgen, PropsExtractor, TypeSystem } from '../../lib/docgen'; import { Component } from '../../blocks/shared'; import { enhancePropTypesProp } from './propTypes/handleProp'; diff --git a/addons/docs/src/frameworks/react/propTypes/renderDefaultValue.ts b/addons/docs/src/frameworks/react/propTypes/createDefaultValue.ts similarity index 69% rename from addons/docs/src/frameworks/react/propTypes/renderDefaultValue.ts rename to addons/docs/src/frameworks/react/propTypes/createDefaultValue.ts index 6d51282c984..ddc4853899d 100644 --- a/addons/docs/src/frameworks/react/propTypes/renderDefaultValue.ts +++ b/addons/docs/src/frameworks/react/propTypes/createDefaultValue.ts @@ -36,7 +36,7 @@ function createSummaryValue(summary: string, detail: string): PropSummaryValue { return { summary, detail }; } -function renderObject({ ast }: InspectionResult): PropDefaultValue { +function generateObject({ ast }: InspectionResult): PropDefaultValue { let prettyCaption = generateCode(ast, true); // Cannot get escodegen to add a space before the last } with the compact mode settings. @@ -50,12 +50,11 @@ function renderObject({ ast }: InspectionResult): PropDefaultValue { : createSummaryValue(OBJECT_CAPTION, generateCode(ast)); } -function renderFunc({ inferedType, ast }: InspectionResult): PropDefaultValue { +function generateFunc({ inferedType, ast }: InspectionResult): PropDefaultValue { const { identifier } = inferedType as InspectionFunction; if (!isNil(identifier)) { return createSummaryValue(getPrettyIdentifier(inferedType), generateCode(ast)); - // return createPropText(getPrettyIdentifier(inferedType), { title: generateCode(ast) }); } const prettyCaption = generateCode(ast, true); @@ -63,15 +62,14 @@ function renderFunc({ inferedType, ast }: InspectionResult): PropDefaultValue { return !isTooLongForDefaultValue(prettyCaption) ? prettyCaption : createSummaryValue(FUNCTION_CAPTION, generateCode(ast)); - - // return !isTooLongForDefaultValue(prettyCaption) - // ? createPropText(prettyCaption) - // : createPropText(FUNCTION_CAPTION, { title: generateCode(ast) }); } // All elements are JSX elements. // JSX elements cannot are not supported by escodegen. -function renderElement(defaultValue: string, inspectionResult: InspectionResult): PropDefaultValue { +function generateElement( + defaultValue: string, + inspectionResult: InspectionResult +): PropDefaultValue { const { inferedType } = inspectionResult; const { identifier } = inferedType as InspectionElement; @@ -85,46 +83,34 @@ function renderElement(defaultValue: string, inspectionResult: InspectionResult) prettyIdentifier, prettyIdentifier !== defaultValue ? defaultValue : undefined ); - - // return createPropText(prettyIdentifier, { - // title: prettyIdentifier !== defaultValue ? defaultValue : undefined, - // }); } } return !isTooLongForDefaultValue(defaultValue) ? defaultValue : createSummaryValue(ELEMENT_CAPTION, defaultValue); - - // return !isTooLongForDefaultValue(defaultValue) - // ? createPropText(defaultValue) - // : createPropText(ELEMENT_CAPTION, { title: defaultValue }); } -function renderArray({ ast }: InspectionResult): PropDefaultValue { +function generateArray({ ast }: InspectionResult): PropDefaultValue { const prettyCaption = generateCode(ast, true); return !isTooLongForDefaultValue(prettyCaption) ? prettyCaption : createSummaryValue(ARRAY_CAPTION, generateCode(ast)); - - // return !isTooLongForDefaultValue(prettyCaption) - // ? createPropText(prettyCaption) - // : createPropText(ARRAY_CAPTION, { title: generateCode(ast) }); } -export function renderDefaultValue(defaultValue: string): PropDefaultValue { +export function createDefaultValue(defaultValue: string): PropDefaultValue { const inspectionResult = inspectValue(defaultValue); switch (inspectionResult.inferedType.type) { case InspectionType.OBJECT: - return renderObject(inspectionResult); + return generateObject(inspectionResult); case InspectionType.FUNCTION: - return renderFunc(inspectionResult); + return generateFunc(inspectionResult); case InspectionType.ELEMENT: - return renderElement(defaultValue, inspectionResult); + return generateElement(defaultValue, inspectionResult); case InspectionType.ARRAY: - return renderArray(inspectionResult); + return generateArray(inspectionResult); default: return null; } diff --git a/addons/docs/src/frameworks/react/propTypes/renderType.ts b/addons/docs/src/frameworks/react/propTypes/createType.ts similarity index 97% rename from addons/docs/src/frameworks/react/propTypes/renderType.ts rename to addons/docs/src/frameworks/react/propTypes/createType.ts index 5ae43650404..5e1e9e4804e 100644 --- a/addons/docs/src/frameworks/react/propTypes/renderType.ts +++ b/addons/docs/src/frameworks/react/propTypes/createType.ts @@ -1,7 +1,6 @@ import { isNil } from 'lodash'; import { PropSummaryValue, PropType } from '@storybook/components'; -import { ExtractedProp } from '../../../lib2/docgen/extractDocgenProps'; -import { DocgenPropType } from '../../../lib2/docgen/types'; +import { ExtractedProp, DocgenPropType } from '../../../lib/docgen'; import { inspectValue } from '../inspection/inspectValue'; import { generateCode } from './generateCode'; import { generateFuncSignature } from './generateFuncSignature'; @@ -41,8 +40,6 @@ interface EnumValue { interface TypeDef { name: string; value: PropSummaryValue; - // caption: string; - // value: string; inferedType?: InspectionType; } @@ -339,7 +336,7 @@ function generateType(type: DocgenPropType, extractedProp: ExtractedProp): TypeD return createTypeDef({ name: 'unknown', summary: 'unknown' }); } -export function renderType(extractedProp: ExtractedProp): PropType { +export function createType(extractedProp: ExtractedProp): PropType { const { type } = extractedProp.docgenInfo; switch (type.name) { diff --git a/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.test.ts b/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.test.ts index 992ef452f59..d7658879844 100644 --- a/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.test.ts +++ b/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.test.ts @@ -1,5 +1,5 @@ import { generateFuncSignature } from './generateFuncSignature'; -import { parseJsDoc } from '../../../lib2/jsdocParser'; +import { parseJsDoc } from '../../../lib/jsdocParser'; it('should return an empty string with there is no @params and @returns tags', () => { const result = generateFuncSignature(null, null); diff --git a/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.ts b/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.ts index c52b9391850..68cc0a5217a 100644 --- a/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.ts +++ b/addons/docs/src/frameworks/react/propTypes/generateFuncSignature.ts @@ -1,5 +1,5 @@ import { isNil } from 'lodash'; -import { ExtractedJsDocParam, ExtractedJsDocReturns } from '../../../lib2/jsdocParser'; +import { ExtractedJsDocParam, ExtractedJsDocReturns } from '../../../lib/jsdocParser'; export function generateFuncSignature( params: ExtractedJsDocParam[], diff --git a/addons/docs/src/frameworks/react/propTypes/handleProp.ts b/addons/docs/src/frameworks/react/propTypes/handleProp.ts index 9199902ca77..e8602850f5c 100644 --- a/addons/docs/src/frameworks/react/propTypes/handleProp.ts +++ b/addons/docs/src/frameworks/react/propTypes/handleProp.ts @@ -1,20 +1,20 @@ import { isNil } from 'lodash'; import { PropDef } from '@storybook/components'; -import { ExtractedProp } from '../../../lib2/docgen/extractDocgenProps'; -import { renderType } from './renderType'; -import { renderDefaultValue } from './renderDefaultValue'; +import { ExtractedProp } from '../../../lib/docgen'; +import { createType } from './createType'; +import { createDefaultValue } from './createDefaultValue'; export function enhancePropTypesProp(extractedProp: ExtractedProp): PropDef { const { propDef } = extractedProp; - const newtype = renderType(extractedProp); + const newtype = createType(extractedProp); if (!isNil(newtype)) { propDef.type = newtype; } const { defaultValue } = extractedProp.docgenInfo; if (!isNil(defaultValue)) { - const newDefaultValue = renderDefaultValue(defaultValue.value); + const newDefaultValue = createDefaultValue(defaultValue.value); if (!isNil(newDefaultValue)) { propDef.defaultValue = newDefaultValue; } diff --git a/addons/docs/src/frameworks/vue/config.tsx b/addons/docs/src/frameworks/vue/config.tsx index a5492d1ff39..e08d3430877 100644 --- a/addons/docs/src/frameworks/vue/config.tsx +++ b/addons/docs/src/frameworks/vue/config.tsx @@ -4,7 +4,7 @@ import toReact from '@egoist/vue-to-react'; import { StoryFn } from '@storybook/addons'; import { addParameters } from '@storybook/client-api'; import { extractProps } from './extractProps'; -import { extractComponentDescription } from '../../lib2/docgen/utils'; +import { extractComponentDescription } from '../../lib/docgen/utils'; addParameters({ docs: { diff --git a/addons/docs/src/frameworks/vue/extractProps.ts b/addons/docs/src/frameworks/vue/extractProps.ts index 27397cf3861..495dd8b0c24 100644 --- a/addons/docs/src/frameworks/vue/extractProps.ts +++ b/addons/docs/src/frameworks/vue/extractProps.ts @@ -1,5 +1,5 @@ import { PropDef } from '@storybook/components'; -import { PropsExtractor, extractPropsFromDocgen, hasDocgen } from '../../lib/docgenUtils'; +import { PropsExtractor, hasDocgen, extractPropsFromDocgen } from '../../lib/docgen'; const SECTIONS = ['props', 'events', 'slots']; @@ -9,7 +9,7 @@ export const extractProps: PropsExtractor = component => { } const sections: Record = {}; SECTIONS.forEach(section => { - sections[section] = extractPropsFromDocgen(component, section); + sections[section] = extractPropsFromDocgen(component, section).map(x => x.propDef); }); return { sections }; }; diff --git a/addons/docs/src/lib2/docgen/renderDefaultValue.ts b/addons/docs/src/lib/docgen/createDefaultValue.ts similarity index 88% rename from addons/docs/src/lib2/docgen/renderDefaultValue.ts rename to addons/docs/src/lib/docgen/createDefaultValue.ts index 7bbcf1a2d53..ec27b7ffe0a 100644 --- a/addons/docs/src/lib2/docgen/renderDefaultValue.ts +++ b/addons/docs/src/lib/docgen/createDefaultValue.ts @@ -8,7 +8,7 @@ function isDefaultValueBlacklisted(value: string) { return BLACKLIST.some(x => x === value); } -export function renderDefaultValue(defaultValue: DocgenPropDefaultValue): PropDefaultValue { +export function createDefaultValue(defaultValue: DocgenPropDefaultValue): PropDefaultValue { if (!isNil(defaultValue)) { const { value } = defaultValue; diff --git a/addons/docs/src/lib2/docgen/createPropDef.ts b/addons/docs/src/lib/docgen/createPropDef.ts similarity index 96% rename from addons/docs/src/lib2/docgen/createPropDef.ts rename to addons/docs/src/lib/docgen/createPropDef.ts index 408a2c27d20..b1ec503d303 100644 --- a/addons/docs/src/lib2/docgen/createPropDef.ts +++ b/addons/docs/src/lib/docgen/createPropDef.ts @@ -2,7 +2,7 @@ import { isNil } from 'lodash'; import { PropDef } from '@storybook/components'; import { TypeSystem, DocgenInfo, DocgenType } from './types'; import { JsDocParsingResult } from '../jsdocParser'; -import { renderDefaultValue } from './renderDefaultValue'; +import { createDefaultValue } from './createDefaultValue'; export type PropDefFactory = ( propName: string, @@ -18,7 +18,7 @@ function createBasicPropDef(name: string, type: DocgenType, docgenInfo: DocgenIn type: type.name, required, description, - defaultValue: renderDefaultValue(defaultValue), + defaultValue: createDefaultValue(defaultValue), }; } diff --git a/addons/docs/src/lib2/docgen/extractDocgenProps.ts b/addons/docs/src/lib/docgen/extractDocgenProps.ts similarity index 100% rename from addons/docs/src/lib2/docgen/extractDocgenProps.ts rename to addons/docs/src/lib/docgen/extractDocgenProps.ts diff --git a/addons/docs/src/lib/docgen/index.ts b/addons/docs/src/lib/docgen/index.ts new file mode 100644 index 00000000000..4116325caa8 --- /dev/null +++ b/addons/docs/src/lib/docgen/index.ts @@ -0,0 +1,3 @@ +export * from './types'; +export * from './utils'; +export * from './extractDocgenProps'; diff --git a/addons/docs/src/lib2/docgen/types.ts b/addons/docs/src/lib/docgen/types.ts similarity index 100% rename from addons/docs/src/lib2/docgen/types.ts rename to addons/docs/src/lib/docgen/types.ts diff --git a/addons/docs/src/lib2/docgen/utils.ts b/addons/docs/src/lib/docgen/utils.ts similarity index 100% rename from addons/docs/src/lib2/docgen/utils.ts rename to addons/docs/src/lib/docgen/utils.ts diff --git a/addons/docs/src/lib/docgenUtils.ts b/addons/docs/src/lib/docgenUtils.ts deleted file mode 100644 index eedad45e6aa..00000000000 --- a/addons/docs/src/lib/docgenUtils.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint-disable no-underscore-dangle */ -import { PropDef, PropsTableProps } from '@storybook/components'; -import { Component } from '../blocks/shared'; - -export type PropsExtractor = (component: Component) => PropsTableProps | null; - -export type PropDefGetter = (component: Component, section: string) => PropDef[]; - -export const hasDocgen = (component: Component) => !!component.__docgenInfo; - -export const extractPropsFromDocgen: PropDefGetter = (component, section) => { - return []; -}; diff --git a/addons/docs/src/lib2/jsdocParser.test.ts b/addons/docs/src/lib/jsdocParser.test.ts similarity index 100% rename from addons/docs/src/lib2/jsdocParser.test.ts rename to addons/docs/src/lib/jsdocParser.test.ts diff --git a/addons/docs/src/lib2/jsdocParser.ts b/addons/docs/src/lib/jsdocParser.ts similarity index 100% rename from addons/docs/src/lib2/jsdocParser.ts rename to addons/docs/src/lib/jsdocParser.ts