Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
Using class-extend
Browse files Browse the repository at this point in the history
  • Loading branch information
revathskumar committed May 15, 2014
1 parent b4b1b3c commit bc90178
Show file tree
Hide file tree
Showing 12 changed files with 527 additions and 552 deletions.
124 changes: 67 additions & 57 deletions all/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,85 @@ var path = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');

module.exports = Generator;
var BackboneGenerator = yeoman.generators.Base.extend({
constructor: function () {
yeoman.generators.Base.apply(this, arguments);

function Generator(args, options, config) {
yeoman.generators.Base.apply(this, arguments);
this.argument('app_name', { type: String, required: false });
this.appname = this.app_name || this.appname;
this.appname = this._.classify(this.appname);

this.dirs = 'models collections views routes helpers templates'.split(' ');
this.env.options.appPath = this.options.appPath || 'app';
this.config.set('appPath', this.env.options.appPath);

this.option('coffee');
this.env.options.appPath = this.options.appPath || 'app';
this.config.set('appPath', this.env.options.appPath);
this.dirs = 'models collections views routes helpers templates'.split(' ');

args = ['application'];
this.option('coffee');

if (this.options.coffee) {
args.push('--coffee');
}
var args = [this.appname];

this.option('requirejs');
this.option('coffee');
this.env.options.appPath = this.options.appPath || 'app';
this.config.set('appPath', this.env.options.appPath);

if (this.options.requirejs) {
args.push('--requirejs');
}
args = ['application'];

if (this.options['template-framework']) {
this.env.options['template-framework'] = this.options['template-framework'];
}
if (this.options.coffee) {
args.push('--coffee');
}

this.testFramework = this.options['test-framework'] || 'mocha';

// the api to hookFor and pass arguments may vary a bit.
this.hookFor('backbone:app', {
args: args
});
this.hookFor('backbone:router', {
args: args
});
this.hookFor('backbone:view', {
args: args
});
this.hookFor('backbone:model', {
args: args
});
this.hookFor('backbone:collection', {
args: args
});

this.hookFor(this.testFramework, {
as: 'app',
options: {
options: {
'skip-install': this.options['skip-install']
}
this.option('requirejs');

if (this.options.requirejs) {
args.push('--requirejs');
}
});

this.on('end', function () {
if (/^.*test$/.test(process.cwd())) {
process.chdir('..');
if (this.options['template-framework']) {
this.env.options['template-framework'] = this.options['template-framework'];
}
this.installDependencies({ skipInstall: this.options['skip-install'] });
});
}

util.inherits(Generator, yeoman.generators.Base);
this.testFramework = this.options['test-framework'] || 'mocha';

// the api to hookFor and pass arguments may vary a bit.
this.hookFor('backbone:app', {
args: args
});
this.hookFor('backbone:router', {
args: args
});
this.hookFor('backbone:view', {
args: args
});
this.hookFor('backbone:model', {
args: args
});
this.hookFor('backbone:collection', {
args: args
});

this.hookFor(this.testFramework, {
as: 'app',
options: {
options: {
'skip-install': this.options['skip-install']
}
}
});

this.on('end', function () {
if (/^.*test$/.test(process.cwd())) {
process.chdir('..');
}
this.installDependencies({ skipInstall: this.options['skip-install'] });
});
},

createDirLayout: function () {
this.dirs.forEach(function (dir) {
this.log.create('app/scripts/' + dir);
this.mkdir(path.join('app/scripts', dir));
}.bind(this));
}
});

Generator.prototype.createDirLayout = function createDirLayout() {
this.dirs.forEach(function (dir) {
this.log.create('app/scripts/' + dir);
this.mkdir(path.join('app/scripts', dir));
}.bind(this));
};
module.exports = BackboneGenerator;
Loading

0 comments on commit bc90178

Please sign in to comment.