
const io = require('path')
const vars_replace = require('./variables-replace')
const shell = require('shelljs')

module.exports = async (options, logger) => {
  let root = process.env.BITBUCKET_CLONE_DIR || process.cwd()
  let {
    source = io.join(root, '.kube'),
    destination = io.join(root, 'kube')
  } = options

  const replace = () => {
    let vars_options = Object.assign(options, { path: destination })
    return vars_replace(vars_options, logger)
  }

  shell.rm('-rf', destination)
  shell.cp('-fR', source, destination)
  return replace();
}