app/src/helpers/inferFlash.js
function findSync(pattern, basePath, findDir) {
  const matches = [];

  (function findSyncRecurse(base) {
    let children;
    try {
      children = fs.readdirSync(base);
    } catch (exception) {
      if (exception.code === 'ENOENT') {
        return;
      }
      throw exception;
    }

    children.forEach((child) => {
      const childPath = path.join(base, child);
      const childIsDirectory = fs.lstatSync(childPath).isDirectory();
      const patternMatches = pattern.test(childPath);

      if (!patternMatches) {
        if (!childIsDirectory) {
          return;
        }
        findSyncRecurse(childPath);
        return;
      }

      if (!findDir) {
        matches.push(childPath);
        return;
      }

      if (childIsDirectory) {
        matches.push(childPath);
      }
    });
  })(basePath);
  return matches;
}
function findSync(pattern, basePath, findDir) {
  const matches = [];

  (function findSyncRecurse(base) {
    let children;
    try {
      children = fs.readdirSync(base);
    } catch (exception) {
      if (exception.code === 'ENOENT') {
        return;
      }
      throw exception;
    }

    children.forEach((child) => {
      const childPath = path.join(base, child);
      const childIsDirectory = fs.lstatSync(childPath).isDirectory();
      const patternMatches = pattern.test(childPath);

      if (!patternMatches) {
        if (!childIsDirectory) {
          return;
        }
        findSyncRecurse(childPath);
        return;
      }

      if (!findDir) {
        matches.push(childPath);
        return;
      }

      if (childIsDirectory) {
        matches.push(childPath);
      }
    });
  })(basePath);
  return matches;
}
function findSync ( pattern , basePath , findDir ) { const matches = [ ] ; ( function findSyncRecurse ( base ) { let children ; try { children = fs . readdirSync ( base ) ; } catch ( exception ) { if ( exception . code === 'ENOENT' ) { return ; } throw exception ; } children . forEach ( ( child ) => { const childPath = path . join ( base , child ) ; const childIsDirectory = fs . lstatSync ( childPath ) . isDirectory ( ) ; const patternMatches = pattern . test ( childPath ) ; if ( ! patternMatches ) { if ( ! childIsDirectory ) { return ; } findSyncRecurse ( childPath ) ; return ; } if ( ! findDir ) { matches . push ( childPath ) ; return ; } if ( childIsDirectory ) { matches . push ( childPath ) ; } } ) ; } ) ( basePath ) ; return matches ; }
Synchronously find a file or directory
@param {RegExp} pattern regex
@param {string} base path
@param {boolean} [findDir] if true, search results will be limited to only directories
@returns {Array}
Synchronously find a file or directory