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


var YiiGenerator = module.exports = function YiiGenerator(args, options, config) {
  yeoman.generators.Base.apply(this, arguments);

  this.on('end', function () {
    this.installDependencies({ skipInstall: options['skip-install'] });
    if (!options['skip-install']) {
        this.composerInstall();
    }
  });

  this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));

  this.composerInstall = function() {
      this.runInstall('composer');
  }
};

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

YiiGenerator.prototype.app = function app() {
  this.mkdir('runtime');

  // Public
  this.mkdir('public');
  this.mkdir('public/assets');
  this.mkdir('public/css');

  // Application
  this.mkdir('app');
  this.mkdir('app/controllers');
  this.mkdir('app/migrations');
  this.mkdir('app/config');
  this.mkdir('app/models');
  this.mkdir('app/views');
  this.mkdir('app/behaviors');

  // Tests
  this.mkdir('tests');

  this.copy('_package.json',  'package.json');
  this.copy('_composer.json', 'composer.json');
  this.copy('_bower.json',    'bower.json');
};

@@ -105,16 +105,111 @@
 ator');%0A
+var http = require('http');%0Avar fs = require('fs');%0Avar spawn = require('child_process').spawn;
 %0A%0Avar Yi
@@ -615,76 +615,487 @@
 %0A%0A  
-this.composerInstall = function() %7B%0A      this.runInstall('composer'
+// Download composer and install composer dependencies%0A  this.composerInstall = function() %7B%0A    var file    = fs.createWriteStream('composer-installer.php');%0A    var request = http.get('http://getcomposer.org/installer', function(response) %7B%0A      response.pipe(file);%0A      spawn('php', %5B'composer-installer.php'%5D).on('exit', function() %7B%0A          fs.unlink('composer-installer.php');%0A          spawn('php', %5B'composer.phar', 'install'%5D, %7B stdio: 'inherit' %7D);%0A      %7D);%0A    %7D
 );%0A 

Add composer downloading and installation