Dir

class
 new Dir() 

The class that manages directories.

class Dir {

collectFiles

method
 Dir.collectFiles() 

Option name Type Description
source String

source path

options Object

option object

return Array

Create an array of all the right files in the source dir

static collectFiles(source, options) {
    var dirtyFiles = walkdir.sync(source), // tee hee!       
      ignore = options.ignore || [],
      files = [];
    dirtyFiles.forEach(function(file) {
      // Parse the file's path
      file = Path.parse(file);
      // Get the file name or subdirectories + file name
      file = file.dir
        .replace(source, '') + Path.sep + file.base;
      // Remove the first path seperator
      file = file.replace(file[0], '');
      if (!ignore.some(folder => file.indexOf(folder) >= 0) && Path.parse(file).ext === '.js') {
        files.push(file);
      }
    });
    return files;
  }

getHomeDir

method
 Dir.getHomeDir() 

Locates the home directory for the
current operating system.
Credits to @cliftonc

static getHomeDir() {
    return osenv.home() ||
      process.env.HOME ||
      process.env.HOMEPATH ||
      process.env.USERPROFILE;
  }

exists

method
 Dir.exists() 

Option name Type Description
path String

The path to the directory

return Boolean

The truth value

Determines if the directory exists

static exists(path) {
    try {
      fs.statSync(Path.normalize(path));
      return true;
    } catch (err) {
      return !(err && err.code === 'ENOENT');
    }
  }

getDirs

method
 Dir.getDirs() 

Option name Type Description
path String

The path to parse.

return Array

The list of directories.

Returns a list of directories from a given path

static getDirs(path) {
  return fs.readdirSync(path)
    .filter(file => fs.statSync(Path.join(path, file)).isDirectory());
}
}
export default Dir;