function filewalker(dir, done) {
  const results = [];

  fs.readdir(dir, async (err, list) => {
    if (err) return done(err);

    let pending = list.length - 1;
    if (!pending) return done(null, results);
    list.forEach(file => {
      file = path.resolve(dir, file);

      fs.stat(file, async (err, stat) => {
        // If directory, execute a recursive call
        if (stat && stat.isDirectory()) {
          let component = file.split('/');
          component = `${file}/${component[component.length - 1]}.jsx`;
          if (fs.existsSync(component)) {
            await new Promise(resolve => {
              loadComponent(component, resolve);
            });
            await results.push(component);
            pending--;
          }
          if (!pending) done(null, results);
        }
      });
    });
  });
}
/**
 * Explores recursively a directory and returns all the filepaths and folderpaths in the callback.
 *
 * @see http://stackoverflow.com/a/5827895/4241030
 * @param {String} dir
 * @param {Function} done
 */
Explores recursively a directory and returns all the filepaths and folderpaths in the callback.
Explores recursively a directory and returns all the filepaths and folderpaths in the callback .
function filewalker(dir, done) {
  const results = [];
  fs.readdir(dir, async (err, list) => {
    if (err) return done(err);
    let pending = list.length - 1;
    if (!pending) return done(null, results);
    list.forEach(file => {
      file = path.resolve(dir, file);
      fs.stat(file, async (err, stat) => {
        if (stat && stat.isDirectory()) {
          let component = file.split('/');
          component = `${file}/${component[component.length - 1]}.jsx`;
          if (fs.existsSync(component)) {
            await new Promise(resolve => {
              loadComponent(component, resolve);
            });
            await results.push(component);
            pending--;
          }
          if (!pending) done(null, results);
        }
      });
    });
  });
}
function filewalker ( dir , done ) { const results = [ ] ; fs . readdir ( dir , async ( err , list ) => { if ( err ) return done ( err ) ; let pending = list . length - 1 ; if ( ! pending ) return done ( null , results ) ; list . forEach ( file => { file = path . resolve ( dir , file ) ; fs . stat ( file , async ( err , stat ) => { if ( stat && stat . isDirectory ( ) ) { let component = file . split ( '/' ) ; component = ` ${ file } ${ component [ component . length - 1 ] } ` ; if ( fs . existsSync ( component ) ) { await new Promise ( resolve => { loadComponent ( component , resolve ) ; } ) ; await results . push ( component ) ; pending -- ; } if ( ! pending ) done ( null , results ) ; } } ) ; } ) ; } ) ; }
Explores recursively a directory and returns all the filepaths and folderpaths in the callback.
Explores recursively a directory and returns all the filepaths and folderpaths in the callback .
// If directory, execute a recursive call