{"size": 1414, "ext": "js", "max_stars_repo_path": "src/finder/index.js", "max_stars_repo_name": "gorriecoe/silverstripe-sanchez", "max_stars_repo_stars_event_min_datetime": "2020-07-17T00:46:37.000Z", "max_stars_repo_stars_event_max_datetime": "2020-07-22T07:02:34.000Z", "max_issues_repo_path": "src/finder/index.js", "max_issues_repo_name": "gorriecoe/silverstripe-sanchez", "max_issues_repo_issues_event_min_datetime": "2021-04-21T11:54:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-21T11:54:02.000Z", "max_forks_repo_path": "src/finder/index.js", "max_forks_repo_name": "gorriecoe/silverstripe-sanchez", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 18.1282051282, "max_line_length": 63, "alphanum_fraction": 0.5975954738}
const glob = require("glob")
const path = require('path')
const homedir = require('os').homedir()
const merge = require('deepmerge')

const defaultOptions = {
  ignore: [
    '**/node_modules/**',
    '**/bower_components/**'
  ]
}

const search = (paths, fileName, options = {}) => {
  let foundFiles = []
  options = merge(
    defaultOptions,
    options
  )
  paths.forEach(filePath => {
    foundFiles = foundFiles.concat(
      glob.sync(
        path.join(filePath, '**', fileName),
        options
      )
    )
  })
  return foundFiles
}

// Convenience method to find all ss yaml config files.
const config = (paths) => {
  return search(
    paths,
    '_config/*.yml',
    {
      ignore: [
        '**/vendor/**'
      ]
    }
  )
}

// Convenience method to find all composer.lock files.
const composer = (paths) => {
  return search(
    paths,
    'composer.lock',
    {
      ignore: [
        '**/vendor/**'
      ]
    }
  )
}

// Convenience method to find all .silverstripe_sanchez files.
// Including the file in home directory.
const sanchez = (paths) => {
  const filename = '.silverstripe_sanchez'
  return [
    path.join(homedir, filename),
    ...search(paths, filename)
  ]
}

// Convenience method to find all node package-lock.json files.
const node = (paths) => {
  return search(paths, 'package-lock.json')
}

module.exports = {
  search,
  config,
  composer,
  sanchez,
  node
}
