var generators = require('yeoman-generator');
var path = require('path');
var _ = require('lodash');

module.exports = generators.Base.extend({
  initializing: function () {
    this.pkg = this.fs.readJSON(this.destinationPath('package.json'), {});

    // Pre set the default props from the information we have at this point
    this.props = {
      name: this.pkg.name,
      description: this.pkg.description,
      version: this.pkg.version,
      homepage: this.pkg.homepage,
      repository: this.pkg.repository
    };

    this.templateFiles = [
      'app.js',
      'index.stache',
      'styles.less',
      'test.html',
      'test.js',
      'models/fixtures.js',
      'models/test.js'
    ]
  },

  prompting: function () {
    var done = this.async();
    var prompts = [{
      name: 'name',
      message: 'Project name',
      when: !this.pkg.name,
      default: process.cwd().split(path.sep).pop()
    }, {
      name: 'short',
      message: 'What is your application short name?',
      default: 'app'
    }, {
      name: 'folder',
      message: 'Project main folder',
      default: 'src'
    }, {
      name: 'description',
      message: 'Description',
      when: !this.pkg.description
    }, {
      name: 'homepage',
      message: 'Project homepage url',
      when: !this.pkg.homepage
    }, {
      name: 'githubAccount',
      message: 'GitHub username or organization',
      when: !this.pkg.repository
    }, {
      name: 'authorName',
      message: 'Author\'s Name',
      when: !this.pkg.author,
      store: true
    }, {
      name: 'authorEmail',
      message: 'Author\'s Email',
      when: !this.pkg.author,
      store: true
    }, {
      name: 'authorUrl',
      message: 'Author\'s Homepage',
      when: !this.pkg.author,
      store: true
    }, {
      name: 'keywords',
      message: 'Key your keywords (comma to split)',
      when: !this.pkg.keywords,
      filter: _.words
    }];

    this.prompt(prompts, function (props) {
      this.props = _.extend(this.props, props);

      this.config.set('short', this.props.short);
      this.config.set('folder', this.props.folder);

      done();
    }.bind(this));
  },

  writing: function () {
    var self = this;
    var pkgJsonFields = {
      name: _.kebabCase(this.props.name),
      version: '0.0.0',
      description: this.props.description,
      homepage: this.props.homepage,
      repository: this.props.repository,
      author: {
        name: this.props.authorName,
        email: this.props.authorEmail,
        url: this.props.authorUrl
      },
      scripts: {
        test: 'testee ' + this.props.folder + '/test.html --browsers firefox --reporter Spec',
        start: 'can-serve --port 8080'
      },
      main: _.kebabCase(this.props.name) + '/index.stache!done-autorender',
      files: [this.props.folder],
      keywords: this.props.keywords,
      system: {
        directories: {
          lib: 'src'
        },
        npmIgnore: ['documentjs', 'testee']
      }
    };

    this.fs.writeJSON('package.json', _.extend(pkgJsonFields, this.pkg));

    this.npmInstall([
      'can@^2.3.0-pre.0',
      'can-connect',
      'steal@^0.11.0-pre.0',
      'jquery',
      'can-ssr',
      'done-autorender',
      'done-css',
      'done-component',
      'yeoman-environment',
      'generator-donejs'
    ], {'save': true});

    this.npmInstall([
      'documentjs@^0.3.0-pre.4',
      'funcunit',
      'steal-qunit',
      'steal-tools@^0.11.0-pre.7',
      'testee'
    ], {'saveDev': true});

    this.templateFiles.forEach(function(name) {
      self.fs.copyTpl(
        self.templatePath(name),
        self.destinationPath(path.join(self.props.folder, name)),
        self.props
      );
    });
  }
});

@@ -2739,41 +2739,9 @@
 in: 
-_.kebabCase(this.props.name) + '/
+'
 inde

Remove package name as part of the main