-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Fix incorrect component name capitalization (#1388)
Fixes #1381 It is happening in a case when react-docgen (any propsParser) is failed and we are trying to guess displayName based on file path. We capitalized every case in the string instead of just words separated by `-` started with small letter. So, by mistake `ButtonTS` in file name becomes `ButtonTs` display name for component when we expect `ButtonTS` Use [startCase]:(https://lodash.com/docs/4.17.11#startCase) and then remove spaces which covers most our cases likemy-buttonTS => MyButtonTS
- Loading branch information
Showing
2 changed files
with
27 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
const path = require('path'); | ||
const _ = require('lodash'); | ||
const { startCase } = require('lodash'); | ||
|
||
function transformFileNameToDisplayName(displayName) { | ||
// ex: your-buttonTS -> Your Button TS -> YourButtonTS | ||
// ex: your_button--TS -> Your Button TS -> YourButtonTS | ||
return startCase(displayName).replace(/\s/g, ''); | ||
} | ||
|
||
module.exports = function getNameFromFilePath(filePath) { | ||
let displayName = path.basename(filePath, path.extname(filePath)); | ||
if (displayName === 'index') { | ||
displayName = path.basename(path.dirname(filePath)); | ||
let fileName = path.basename(filePath, path.extname(filePath)); | ||
if (fileName === 'index') { | ||
fileName = path.basename(path.dirname(filePath)); | ||
} | ||
|
||
return _.upperFirst(_.camelCase(displayName)); | ||
return transformFileNameToDisplayName(fileName); | ||
}; |