'use strict';

var path = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');

exports = module.exports = function(args, options) {
  yeoman.generators.Base.apply(this, arguments);
  this.basename = path.basename(options.env.cwd);
  // this.on('end', function() {
  //   this.installDependencies({
  //     skipInstall: options['skip-install']
  //   });
  // });
}

util.inherits(exports, yeoman.generators.Base);

exports.prototype.askFor = function() {
  var done = this.async();
  console.log(this.yeoman);

  this.prompt([
    {
      name: 'name',
      message: 'Project name',
      "default": this.basename
    }, {
      name: 'description',
      message: 'Description',
      "default": ''
    }, {
      name: 'version',
      message: 'Version',
      "default": '0.0.0'
    }, {
      name: 'author',
      message: 'Author',
      "default": this.user.git.username
    }, {
      name: 'email',
      message: 'Email',
      "default": this.user.git.email
    }, {
      name: 'usingGithub',
      message: 'Using GitHub?',
      type: 'confirm',
      "default": true
    }, {
      name: 'githubUser',
      message: 'GitHub user',
      "default": function(answers) {
        var githubUser = this.shell.exec('git config --get github.user', {silent: true}).output.trim();
        return githubUser || answers.author;
      }.bind(this),
      when: function(answers) {
        return answers.usingGithub;
      }
    }, {
      name: 'githubRepo',
      message: 'GitHub repo',
      "default": function(answers) {
        return answers.name;
      }.bind(this),
      when: function(answers) {
        return answers.usingGithub;
      }
    }, {
      name: 'licenses',
      message: 'Licenses',
      type: 'checkbox',
      choices: [{name: 'MIT', checked: true}, 'Apache-2.0', 'MPL-2.0', 'GPL-2.0'],
      "default": 'MIT',
      when: function(answers) {
        return answers.usingGithub;
      }
    }
  ], function(props) {
    this._.extend(this, props);
    done();
  }.bind(this));
};

exports.prototype.copyRootFile = function() {
  this.directory('root', '.');
};

exports.prototype.copyLicenses = function() {
  if (!this.licenses || this._.isEmpty(this.licenses)) {
    return;
  };
  this._.each(this.licenses, function(license) {
    var licenseFile = 'LICENSE-' + license;
    this.template('licenses/' + licenseFile, licenseFile);
  }.bind(this));
};

exports.prototype.copyTemplateFiles = function() {
  this.template('_README.md', 'README.md');
  this.template("_package.json", 'package.json');
};

exports.prototype.copyAppFiles = function() {
  this.mkdir('app/templates/root');
  this.mkdir('app/templates/licenses');
  this.copy('app/index.js');
  this.directory('root', 'app/templates/root');
  this.directory('licenses', 'app/templates/licenses');
}

@@ -260,19 +260,16 @@
 .cwd);%0A 
- //
  this.on
@@ -290,19 +290,16 @@
 on() %7B%0A 
- //
    this.
@@ -326,15 +326,12 @@
 %7B%0A  
-//
     
- 
 skip
@@ -368,19 +368,16 @@
 '%5D%0A 
- //
    %7D);%0A 
  // 
@@ -376,11 +376,8 @@
 );%0A 
- //
  %7D);
@@ -2613,102 +2613,29 @@
 his.
-mk
 dir
-('app/templates/root');%0A  this.mkdir('app/templates/licenses');%0A  this.copy('app/index.js
+ectory('app', 'app
 ');%0A

make app/index.js more concise