'use strict';
const _ = require('lodash');
const extend = require('lodash').merge;
const Generators = require('yeoman-generator');

module.exports =  class extends Generators {
  constructor(args, options) {
    super(args, options);
    this.option('generateInto', {
      type: String,
      required: false,
      defaults: '',
      desc: 'Relocate the location of the generated files.'
    });

    this.option('name', {
      type: String,
      required: true,
      desc: 'The new module name.'
    });
  }

  initializing() {
    this.fs.copy(
      this.templatePath('index.js'),
      this.destinationPath(this.options.generateInto, 'src/index.js')
    );

    this.fs.copy(
      this.templatePath('eslintrc'),
      this.destinationPath(this.options.generateInto, 'test/.eslintrc')
    );

    this.fs.copyTpl(
      this.templatePath('karma.conf.js'),
      this.destinationPath(this.options.generateInto, 'karma.conf.js'),
      {
        pkgSafeName: _.camelCase(this.options.name),
        travis: this.options.travis
      }
    );

    this.fs.copy(
      this.templatePath('tests.webpack.js'),
      this.destinationPath(this.options.generateInto, 'tests.webpack.js')
    );

    this.fs.copyTpl(
      this.templatePath('test.js'),
      this.destinationPath(this.options.generateInto, 'test/' + this.options.name + '-test.js'), {
        pkgName: this.options.name,
        pkgSafeName: _.camelCase(this.options.name)
      }
    );
  }

  writing() {
    const pkg = this.fs.readJSON(this.destinationPath(this.options.generateInto, 'package.json'), {});

    extend(pkg, {
      peerDependencies: {
        "react": "^15.6.1",
        "react-dom": "^15.6.1"
      },
      devDependencies: {
        "rimraf": "^2.5.4",
        "karma": "^1.2.0",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-mocha": "^1.1.1",
        "karma-sourcemap-loader": "^0.3.7",
        "karma-webpack": "^1.8.0",
        "chai": "^3.5.0",
        "react-addons-test-utils": "^15.6.1",
        "enzyme": "^2.4.1",
        "webpack": "3.5.5",
        "babel-loader": "^6.2.3",
        "mocha": "^3.2.0"
      },
      scripts: {
        "clean": "rimraf lib dist",
        "check:src": "npm run lint && npm run test",
        "test": "cross-env BABEL_ENV=test karma start --single-run",
        "test:watch": "cross-env BABEL_ENV=test karma start"
      }
    });

    this.fs.writeJSON(this.destinationPath(this.options.generateInto, 'package.json'), pkg);
  }
}

@@ -1593,102 +1593,8 @@
 , %7B%0A
-      peerDependencies: %7B%0A        %22react%22: %22%5E15.6.1%22,%0A        %22react-dom%22: %22%5E15.6.1%22%0A      %7D,%0A
     
@@ -1923,17 +1923,17 @@
  %22%5E15.6.
-1
+0
 %22,%0A     
@@ -2042,16 +2042,76 @@
 %22%5E3.2.0%22
+,%0A        %22react%22: %22%5E15.6.1%22,%0A        %22react-dom%22: %22%5E15.6.1%22
 %0A      %7D

fix module version