Created
September 1, 2016 03:05
-
-
Save jwietelmann/2141cddb92318a04b996686b9fd175c2 to your computer and use it in GitHub Desktop.
A hack to use `react-docgen` to iterate over all React component files in a directory tree.
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
'use strict' | |
const reactDocs = require('react-docgen') | |
const dir = require('node-dir') | |
export default function walkReactComponentFiles(path, pattern, handleFilename, done) { | |
const iterator = function(error, content, filename, next) { | |
if(error) { | |
throw error | |
} | |
try { | |
reactDocs.parse(content) | |
} catch(parseError) { | |
return next() // Skip non-components. | |
} | |
handleFilename(filename) | |
return next() | |
} | |
dir.readFiles(path, {match: pattern}, iterator, done) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment