const { join } = require('path');
const glob = require('glob');
const mkdirp = require('mkdirp');
const BasicGenerator = require('../../BasicGenerator');
const { validateFolder } = require('../../utils')

class FiresoonGenerator extends BasicGenerator {
    prompting() {
      const prompts = [
        {
          type: 'input',
          name: 'appName',
          message: '请输入项目名称 (quickstart):',
          default: 'quickstart',
          validate: input => validateFolder(input)
        },
        {
          type: 'input',
          name: 'description',
          message: '请输入项目描述 (description):',
          default: 'description'
        },
        {
          type: 'input',
          name: 'version',
          message: '请输入项目版本 (1.0.0):',
          default: '1.0.0'
        }
      ];
      return this.prompt(prompts).then(props => {
          this.prompts = props;
      });
    }

    writing() {

      const { appName, description, version } = this.prompts;
      mkdirp.sync(`${appName}`);
      this.destinationRoot(`${appName}`);
      this.initGit(this.destinationRoot())

      let pkg = this.fs.readJSON(this.templatePath('./package-tmpl.json'), {});
      pkg.name = `${appName}`;
      pkg.description = description;
      pkg.version = version;
      pkg = {
        ...pkg,
      };
      this.fs.writeJSON(this.destinationPath('package.json'), pkg);
      this.copyFiles({
        context: this.prompts,
      }, join(this.templatePath(), './ie8-pro'));
    }
}

module.exports = FiresoonGenerator;
