{"size": 760, "ext": "js", "max_stars_repo_path": "lib/components/utils/file.utils.js", "max_stars_repo_name": "ukayani/auth0-deploy", "max_stars_repo_stars_event_min_datetime": "2017-08-14T07:02:30.000Z", "max_stars_repo_stars_event_max_datetime": "2017-10-18T23:07:39.000Z", "max_issues_repo_path": "lib/components/utils/file.utils.js", "max_issues_repo_name": "ukayani/auth0-deploy", "max_issues_repo_issues_event_min_datetime": "2017-08-12T00:28:55.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-12T07:18:02.000Z", "max_forks_repo_path": "lib/components/utils/file.utils.js", "max_forks_repo_name": "ukayani/auth0-deploy", "max_forks_repo_forks_event_min_datetime": "2017-08-21T15:57:59.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-25T14:27:53.000Z"}
{"max_stars_count": 3, "max_issues_count": 9, "max_forks_count": 4, "avg_line_length": 21.7142857143, "max_line_length": 55, "alphanum_fraction": 0.5868421053}
'use strict';
const co = require('bluebird').coroutine;
const fs = require('mz/fs');
const path = require('path');

const getFileContent = (file) => {
  return fs.readFile(file, 'utf-8').catch(() => {
    throw new Error(`Could not find file ${file}`);
  });
};

const getDirectories = (dir) => {
  return co(function* () {
    const files = yield fs.readdir(dir);

    const directories = [];
    for (let i in files) {
      const f = files[i];
      const file = yield fs.stat(path.join(dir, f));
      if (file.isDirectory()) {
        directories.push(path.join(dir, f));
      }
    }

    return directories;
  })().catch(() => {
    throw new Error(`Could not find directory ${dir}`);
  });
};

module.exports = {
  getFileContent,
  getDirectories
};
