const _ = require('lodash');
const fountain = require('fountain-generator');

module.exports = fountain.Base.extend({
  prompting() {
    this.fountainPrompting();
  },

  configuring: {
    pkg() {
      const pkg = {
        devDependencies: {
          // https://github.com/babel/babel-eslint/issues/267
          'eslint': '2.2.x',
          'eslint-config-xo-space': '^0.10.0'
        },
        eslintConfig: {
          env: {
            browser: true,
            jasmine: true
          }
        }
      };

      if (this.props.modules === 'webpack') {
        _.merge(pkg, {
          devDependencies: {
            'eslint-loader': '^1.3.0',
            'babel-loader': '^6.2.0'
          }
        });
        if (this.props.framework === 'react') {
          _.merge(pkg, {devDependencies: {'babel-preset-react': '^6.1.18'}});
        }
      } else {
        _.merge(pkg, {devDependencies: {'gulp-eslint': '^2.0.0'}});
      }

      if (this.props.js === 'babel') {
        _.merge(pkg, {
          devDependencies: {
            'babel-eslint': '^5.0.0',
            'eslint-plugin-babel': '^3.1.0'
          },
          eslintConfig: {
            extends: [
              'xo-space/esnext'
            ]
          }
        });
      }

      if (this.props.js === 'js') {
        _.merge(pkg, {
          eslintConfig: {
            extends: [
              'xo-space'
            ]
          }
        });
      }

      if (this.props.framework === 'angular2' && this.props.js !== 'typescript') {
        _.merge(pkg, {
          eslintConfig: {
            rules: {
              'new-cap': [2, {capIsNewExceptions: ['Input', 'Output', 'Component', 'View', 'Injectable', 'RouteConfig', 'Class']}]
            }
          }
        });
      }

      if (this.props.modules === 'inject') {
        if (this.props.framework === 'angular1') {
          _.merge(pkg, {
            eslintConfig: {
              globals: {
                angular: true
              }
            }
          });
        }
        if (this.props.js === 'babel' || this.props.js === 'js' && this.props.framework === 'react') {
          _.merge(pkg, {devDependencies: {'gulp-babel': '^6.1.0'}});
        }
      }

      if (this.props.modules === 'systemjs') {
        _.merge(pkg, {eslintConfig: {globals: {SystemJS: true}}});

        if (this.props.framework === 'angular2') {
          _.merge(pkg, {
            jspm: {
              devDependencies: {
                'babel-plugin-angular2-annotations': 'npm:babel-plugin-angular2-annotations@^5.0.0',
                'babel-plugin-transform-decorators-legacy': 'npm:babel-plugin-transform-decorators-legacy@^1.3.4',
                'babel-plugin-transform-class-properties': 'npm:babel-plugin-transform-class-properties@^6.6.0',
                'babel-plugin-transform-flow-strip-types': 'npm:babel-plugin-transform-flow-strip-types@^6.6.4'
              }
            }
          });
        } else if (this.props.framework === 'react') {
          _.merge(pkg, {jspm: {devDependencies: {'babel-preset-react': 'npm:babel-preset-react@^6.5.0'}}});
        }

        if (this.props.js !== 'typescript') {
          _.merge(pkg, {
            jspm: {
              dependencies: {babel: 'npm:babel-core@^6.6.5'},
              devDependencies: {'plugin-babel': 'npm:systemjs-plugin-babel@^0.0.8'}
            }
          });
        }
      }

      if (this.props.js === 'babel' || this.props.js === 'js' && this.props.framework === 'react') {
        _.merge(pkg, {devDependencies: {'babel-core': '^6.2.0'}});
      }

      if (this.props.js === 'babel') {
        _.merge(pkg, {devDependencies: {'babel-preset-es2015': '^6.2.0'}});
      }

      this.mergeJson('package.json', pkg);
    }
  },

  writing: {
    wireing() {
      if (this.props.modules === 'webpack' && this.props.js !== 'typescript') {
        this.replaceInFileWithTemplate(
          'conf/webpack.conf.js',
          'conf/webpack.conf.js',
          / {2}module: \{/
        );
        this.replaceInFileWithTemplate(
          'conf/webpack.conf.js',
          'conf/webpack-test.conf.js',
          / {2}module: \{/
        );
      } else if (this.props.modules === 'systemjs') {
        this.copyTemplate(
          'gulp_tasks/scripts-full.js',
          'gulp_tasks/scripts.js'
        );
      } else if (this.props.modules === 'inject' && this.props.js !== 'typescript') {
        this.replaceInFileWithTemplate(
          'gulp_tasks/scripts-require.js',
          'gulp_tasks/scripts.js',
          /const gulp = require\('gulp'\);/
        );
        this.replaceInFileWithTemplate(
          'gulp_tasks/scripts-stream.js',
          'gulp_tasks/scripts.js',
          / {2}return gulp\.src[^\n]*/
        );
      }
    }
  }
});

@@ -243,70 +243,8 @@
 : %7B%0A
-          // https://github.com/babel/babel-eslint/issues/267%0A
     
@@ -264,11 +264,12 @@
 ': '
+%5E
 2.
-2
+4
 .x',
@@ -999,21 +999,28 @@
 int': '%5E
-5
+6
 .0.0
+-beta.6
 ',%0A     

Remove workaround and update eslint/babel-eslint to solve 'estraverse-fb' issue https://github.com/babel/babel-eslint/issues/267#issuecomment-196376577