const path = require('path')
const yeoman = require('yeoman-generator')

const dependencies = [
  'weex-html5',
]

const devDependencies = [
  'eslint',
  'eslint-config-weex',
  'serve',
  'webpack',
  'weex-loader',
]

module.exports = yeoman.Base.extend({

  constructor: function () {
    yeoman.Base.apply(this, arguments)

    // compose with Android and iOS generator
    const args = { args: arguments[0], options: this.options }
    this.composeWith('weex:android', args, {
      local: require.resolve(path.resolve(__dirname, 'android'))
    })
    this.composeWith('weex:ios', args, {
      local: require.resolve(path.resolve(__dirname, 'ios'))
    })
  },

  configuring: function() {
  },

  writing: function() {
    this.fs.copy(this.templatePath('**/*'), this.destinationPath())

    // const copyTo = (src, dist) => {
    //   if (src && dist) {
    //     this.fs.copy(this.templatePath(src), this.destinationPath(dist))
    //   }
    // }

    // copyTo('_gitignore', '.gitignore')
    // copyTo('android', 'android')
    // copyTo('_buckconfig', '.buckconfig')
  },

  install: function() {
    // this.npmInstall(dependencies, { save: true })
    // this.npmInstall(devDependencies, { saveDev: true })
  },

  end: function() {
  }
})

const path = require('path')
const yeoman = require('yeoman-generator')

const dependencies = [
  'weex-html5',
]

const devDependencies = [
  'eslint',
  'eslint-config-weex',
  'serve',
  'webpack',
  'weex-loader',
]

module.exports = yeoman.Base.extend({

  constructor: function () {
    yeoman.Base.apply(this, arguments)

    // compose with Android and iOS generator
    const args = { args: arguments[0], options: this.options }
    this.composeWith('weex:android', args, {
      local: require.resolve(path.resolve(__dirname, 'android'))
    })
    this.composeWith('weex:ios', args, {
      local: require.resolve(path.resolve(__dirname, 'ios'))
    })
  },

  configuring: function() {
  },

  writing: function() {
    // this.fs.copy(this.templatePath('**/*'), this.destinationPath())

    const copy = (file, dist) => {
      this.fs.copy(this.templatePath(file), this.destinationPath(file))
    }

    copy('README.md')
    copy('webpack.config.js')
    copy('package.json')
    copy('src/index.we')
    copy('web/index.html')
  },

  install: function() {
    // this.npmInstall(dependencies, { save: true })
    // this.npmInstall(devDependencies, { saveDev: true })
  },

  end: function() {
  }
})

copy templates file explicitly