From 9d5b12983c1f40ffd3bfa5c3debb4ca8448db3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Sat, 14 Dec 2019 10:06:54 +0100 Subject: [PATCH] feat(docz-core): support kebab & pascal case component file name pattern (#1314) --- core/docz/package.json | 2 ++ core/docz/src/components/Props.tsx | 18 +++++++++++++----- yarn.lock | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/core/docz/package.json b/core/docz/package.json index 16d6e2c82..9461f8282 100644 --- a/core/docz/package.json +++ b/core/docz/package.json @@ -36,6 +36,7 @@ "lodash": "^4.17.14", "marksy": "^8.0.0", "match-sorter": "^3.1.1", + "pascal-case": "^3.1.0", "prop-types": "^15.7.2", "scheduler": "^0.15.0", "ulid": "^2.3.0", @@ -49,6 +50,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.2.0", "@types/lodash": "^4.14.136", "@types/node": "^12.6.8", + "@types/pascal-case": "^1.1.2", "@types/reach__router": "^1.2.4", "@types/react": "^16.8.23", "@types/react-dom": "^16.8.4", diff --git a/core/docz/src/components/Props.tsx b/core/docz/src/components/Props.tsx index 9a983ff18..bddcfc429 100644 --- a/core/docz/src/components/Props.tsx +++ b/core/docz/src/components/Props.tsx @@ -1,8 +1,9 @@ import * as React from 'react' import { createElement, SFC, ComponentType, useMemo } from 'react' -import { assoc, first, get, mapValues } from 'lodash/fp' +import { assoc, first, get, mapValues, kebabCase } from 'lodash/fp' import capitalize from 'capitalize' import marksy from 'marksy' +import { pascalCase } from 'pascal-case' import { doczState } from '../state' import { useComponents } from '../hooks' @@ -117,13 +118,20 @@ export const Props: SFC = ({ const componentName = filemetaName || get('displayName', component) || get('name', component) + const componentMatcher = (componentName: string, item: any) => { + const matchingPatterns = [ + filename, + `/${componentName}.`, + `/${kebabCase(componentName)}.`, + `/${pascalCase(componentName)}.`, + ] + return !!matchingPatterns.find(pattern => item.key.includes(pattern)) + } + const found = stateProps && stateProps.length > 0 && - stateProps.find( - item => - item.key.includes(`/${componentName}.`) || item.key.includes(filename) - ) + stateProps.find(item => componentMatcher(componentName, item)) const value = get('value', found) || [] const firstDefinition = first(value) diff --git a/yarn.lock b/yarn.lock index b4ed78497..f5e89ab71 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2901,6 +2901,13 @@ resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== +"@types/pascal-case@^1.1.2": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@types/pascal-case/-/pascal-case-1.1.2.tgz#9061da7ae95356c1fb85168f460bcb861dc3eb21" + integrity sha1-kGHaeulTVsH7hRaPRgvLhh3D6yE= + dependencies: + pascal-case "*" + "@types/prettier@^1.16.4": version "1.16.4" resolved "https://registry.npmjs.org/@types/prettier/-/prettier-1.16.4.tgz#5e5e97702cb68498aaba7349b941648daaf2385c" @@ -12824,6 +12831,13 @@ lower-case@^1.1.0, lower-case@^1.1.1, lower-case@^1.1.2: resolved "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz#9a2cabd1b9e8e0ae993a4bf7d5875c39c42e8eac" integrity sha1-miyr0bno4K6ZOkv31YdcOcQujqw= +lower-case@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/lower-case/-/lower-case-2.0.1.tgz#39eeb36e396115cc05e29422eaea9e692c9408c7" + integrity sha512-LiWgfDLLb1dwbFQZsSglpRj+1ctGnayXz3Uv0/WO8n558JycT5fg6zkNcnW0G68Nn0aEldTFeEfmjCfmqry/rQ== + dependencies: + tslib "^1.10.0" + lowercase-keys@1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306" @@ -13696,6 +13710,14 @@ no-case@^2.2.0, no-case@^2.3.2: dependencies: lower-case "^1.1.1" +no-case@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.2.tgz#2b03928510318591854c0423e504d13b21234263" + integrity sha512-Yber3mEOA3T9+as7Z70TJUQCUPRmmq6s8NmsZX5aSB1qk+Mt+3a5JVPpnAnONUShLTkMDF4PJY3h0GKlXdRTNA== + dependencies: + lower-case "^2.0.1" + tslib "^1.10.0" + node-abi@^2.7.0: version "2.8.0" resolved "https://registry.npmjs.org/node-abi/-/node-abi-2.8.0.tgz#bd2e88dbe6a6871e6dd08553e0605779325737ec" @@ -14674,6 +14696,14 @@ parseurl@^1.3.2, parseurl@~1.3.2, parseurl@~1.3.3: resolved "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ== +pascal-case@*, pascal-case@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/pascal-case/-/pascal-case-3.1.0.tgz#b3cc1273a957ceb0c37c029d2580ed59f585e4df" + integrity sha512-7cINxTsRAFym4dLVMdObWx2wr/FjVz8BfCdLPC069kAFLal/5dZhxObpAIM40GwZ/Xik1J37z+Nw6/TVy5fmIg== + dependencies: + no-case "^3.0.2" + tslib "^1.10.0" + pascal-case@^2.0.0: version "2.0.1" resolved "https://registry.npmjs.org/pascal-case/-/pascal-case-2.0.1.tgz#2d578d3455f660da65eca18ef95b4e0de912761e"