Skip to content

Instantly share code, notes, and snippets.

@jwietelmann
Created September 1, 2016 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwietelmann/2141cddb92318a04b996686b9fd175c2 to your computer and use it in GitHub Desktop.
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.
'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