import pick from 'lodash/pick'
import mapValues from 'lodash/mapValues'
import fsx from 'fs-extra-promise'

export default (options = {}, context = {}) => {
  const host = options.host || options.project || context.project

  const {
    methods = [
      'walk',
      'outputJson',
      'writeFile',
      'readFile',
      'readdir',
      'readJson',
      'writeJson',
      'outputFile',
      'exists',
      'mkdirp',
      'copy',
      'move',
      'mkdtemp',
      'remove',
      'ensure',
      'ensureDir',
      'isDirectory',
    ]
  } = options

  methods.push(...methods.map(name => `${name}Sync`))
  methods.push(...methods.map(name => `${name}Async`))

  host.hide('fsx', pick(fsx, methods))
  host.hide('fs', host.fsx)

  // proxy the methods from directly on the host
  mapValues(host.fsx, (fn, name) => (
    host.hide(name, (...args) => host.fsx[name](...args))
  ))

  return host
}
