Skip to content

Commit

Permalink
feat(docz-core): support kebab & pascal case component file name patt…
Browse files Browse the repository at this point in the history
…ern (#1314)
  • Loading branch information
axe312ger authored and rakannimer committed Dec 14, 2019
1 parent 5fc0527 commit 9d5b129
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/docz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
18 changes: 13 additions & 5 deletions core/docz/src/components/Props.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -117,13 +118,20 @@ export const Props: SFC<PropsProps> = ({
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)
Expand Down
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 9d5b129

Please sign in to comment.