'use strict';
const normalizeUrl = require('normalize-url');
const humanizeUrl = require('humanize-url');
const Generator = require('yeoman-generator');
const _s = require('underscore.string');

module.exports = class extends Generator {
	init () {
		return this.prompt([{
			name: 'moduleName',
			message: 'What do you want to name your module?',
			default: this.appname.replace(/\s/g, '-'),
			filter: function (val) {
				return _s.slugify(val);
			}
		}, {
			name: 'githubUsername',
			message: 'What is your GitHub username?',
			store: true,
			validate: function (val) {
				return val.length > 0 ? true : 'You have to provide a username';
			}
		}, {
			name: 'website',
			message: 'What is the URL of your website?',
			store: true,
			validate: function (val) {
				return val.length > 0 ? true : 'You have to provide a website URL';
			},
			filter: function (val) {
				return normalizeUrl(val);
			}
		}, {
			name: 'cli',
			message: 'Do you need a CLI?',
			type: 'confirm',
			default: false
		}]).then(function (props) {
			const tpl = {
				moduleName: props.moduleName,
				camelModuleName: _s.camelize(props.moduleName),
				githubUsername: props.githubUsername,
				name: this.user.git.name(),
				email: this.user.git.email(),
				website: props.website,
				humanizedWebsite: humanizeUrl(props.website),
				cli: props.cli
			};

			const mv = function (from, to) {
				this.fs.move(this.destinationPath(from), this.destinationPath(to));
			}.bind(this);

			this.fs.copyTpl([
				this.templatePath() + '/**',
				'!**/cli.js'
			], this.destinationPath(), tpl);

			if (props.cli) {
				this.fs.copyTpl(this.templatePath('cli.js'), this.destinationPath('cli.js'), tpl);
			}

			mv('editorconfig', '.editorconfig');
			mv('eslintrc', '.eslintrc');
			mv('gitattributes', '.gitattributes');
			mv('gitignore', '.gitignore');
			mv('travis.yml', '.travis.yml');
			mv('tachikoma.yml', '.tachikoma.yml');
			mv('_package.json', 'package.json');
		}.bind(this));
	}
	install () {
		this.installDependencies({
			bower: false,
			callback: this._injectDependencies.bind(this)
		});
	}
	_injectDependencies () {
		this.spawnCommandSync('npm', ['run', 'fixpack']);
	}
};

@@ -403,35 +403,12 @@
 er: 
-function (val) %7B%0A%09%09%09%09return
+x =%3E
  _s.
@@ -415,26 +415,18 @@
 slugify(
-val);%0A%09%09%09%7D
+x)
 %0A%09%09%7D, %7B%0A
@@ -530,39 +530,14 @@
 te: 
-function (val) %7B%0A%09%09%09%09return val
+x =%3E x
 .len
@@ -585,22 +585,16 @@
 sername'
-;%0A%09%09%09%7D
 %0A%09%09%7D, %7B%0A
@@ -694,39 +694,14 @@
 te: 
-function (val) %7B%0A%09%09%09%09return val
+x =%3E x
 .len
@@ -752,22 +752,16 @@
 ite URL'
-;%0A%09%09%09%7D
 ,%0A%09%09%09fil
@@ -769,35 +769,12 @@
 er: 
-function (val) %7B%0A%09%09%09%09return
+x =%3E
  nor
@@ -787,18 +787,10 @@
 Url(
-val);%0A%09%09%09%7D
+x)
 %0A%09%09%7D
@@ -895,25 +895,17 @@
 then
-(function 
 (props
-)
+ =%3E
  %7B%0A%09
@@ -1235,17 +1235,8 @@
 mv =
- function
  (fr
@@ -1242,16 +1242,19 @@
 rom, to)
+ =%3E
  %7B%0A%09%09%09%09t
@@ -1324,27 +1324,16 @@
 ));%0A%09%09%09%7D
-.bind(this)
 ;%0A%0A%09%09%09th
@@ -1817,27 +1817,16 @@
 n');%0A%09%09%7D
-.bind(this)
 );%0A%09%7D%0A%09i

remove function keyword