-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from alfa-laboratory/feat/superior-proptypes-pa…
…rser feat(typings): allow to get component info separate to typings
- Loading branch information
Showing
13 changed files
with
190 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ module.exports = { | |
rules: { | ||
'func-names': 0 | ||
} | ||
}; | ||
}; |
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
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function isDecoratedBy(path, decoratorName = 'cn') { | ||
const decorators = path.get('decorators'); | ||
if (decorators && decorators.value) { | ||
return decorators.value | ||
.some(decorator => decorator.expression.callee && decorator.expression.callee.name === decoratorName); | ||
} | ||
return false; | ||
} | ||
|
||
module.exports = isDecoratedBy; |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const path = require('path'); | ||
const reactDocGen = require('react-docgen'); | ||
const getSourceFileContent = require('./get-source-file-content'); | ||
const createResolver = require('./create-resolver'); | ||
const createDisplayNameHandler = require('react-docgen-displayname-handler').createDisplayNameHandler; | ||
|
||
const documentation = {}; | ||
const defaultHandlers = [ | ||
reactDocGen.handlers.propTypeHandler, | ||
reactDocGen.handlers.propTypeCompositionHandler, | ||
reactDocGen.handlers.propDocBlockHandler, | ||
reactDocGen.handlers.flowTypeHandler, | ||
reactDocGen.handlers.flowTypeDocBlockHandler, | ||
reactDocGen.handlers.defaultPropsHandler, | ||
reactDocGen.handlers.componentDocblockHandler, | ||
reactDocGen.handlers.displayNameHandler, | ||
reactDocGen.handlers.componentMethodsHandler, | ||
reactDocGen.handlers.componentMethodsJsDocHandler | ||
]; | ||
|
||
function getReactComponentInfo(filePath, parentPath) { | ||
if (documentation[filePath]) { | ||
return documentation[filePath]; | ||
} | ||
|
||
const src = getSourceFileContent(filePath, parentPath); | ||
const content = src.content; | ||
filePath = src.filePath; | ||
const info = reactDocGen.parse( | ||
content, | ||
createResolver(filePath), | ||
defaultHandlers.concat(createDisplayNameHandler(filePath)) | ||
); | ||
info.filePath = filePath; | ||
if (info.composes) { | ||
info.composes = info.composes | ||
.map(relativePath => getReactComponentInfo(relativePath, path.dirname(filePath))); | ||
} else { | ||
info.composes = []; | ||
} | ||
// extends props for composed components | ||
const composeProps = info.composes.reduce((prev, item) => Object.assign({}, prev, item.props), {}); | ||
info.props = Object.assign(composeProps || {}, info.props || {}); // own props should have higher priority | ||
documentation[filePath] = info; | ||
return info; | ||
} | ||
|
||
module.exports = getReactComponentInfo; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.