generator-node-boilerplate
Version:
Web application generator for Yeoman
160 lines (133 loc) • 6.05 kB
JavaScript
'use strict';
var crypto = require('crypto');
var yeoman = require('yeoman-generator');
var yosay = require('yosay');
var NodeBoilerplateGenerator = yeoman.generators.Base.extend({
init: function() {
this.pkg = require('../package.json');
this.on('end', function() {
if(!this.options['skip-install']) {
this.installDependencies();
}
});
},
askFor: function() {
var done = this.async();
// Have Yeoman greet the user.
this.log(yosay('Welcome to the marvelous NodeBoilerplate generator!'));
var prompts = [{
name: 'appName',
message: 'What would you like to call your application?',
default: 'newproject'
},{
name: 'githubUser',
message: 'Would you mind providing me your username on Github',
default: 'someuser'
}];
this.prompt(prompts, (function(_this) {
return function(props) {
_this.appName = props.appName;
_this.githubUser = props.githubUser;
_this.sessionSecret = crypto.randomBytes(256);
done();
};
})(this));
},
app: function() {
// Create the application file structure.
this.mkdir('app');
this.mkdir('app/coffeescript');
this.mkdir('app/coffeescript/components');
this.mkdir('app/coffeescript/controllers');
this.mkdir('app/coffeescript/helpers');
this.mkdir('app/coffeescript/models');
this.mkdir('app/coffeescript/routes');
this.mkdir('app/coffeescript/views');
this.mkdir('app/scss');
this.mkdir('app/scss/reset');
this.mkdir('app/scss/responsive');
this.mkdir('app/templates');
this.mkdir('app/templates/todos');
this.mkdir('config');
this.mkdir('models');
this.mkdir('public');
this.mkdir('public/javascripts');
this.mkdir('public/stylesheets');
this.mkdir('public/images');
this.mkdir('routes');
this.mkdir('routes/v1');
this.mkdir('tasks');
this.mkdir('spec');
this.mkdir('spec/routes');
this.mkdir('spec/routes/v1');
this.mkdir('views');
// Copy the build scripts.
this.template('_gruntfile.coffee', 'Gruntfile.coffee');
// Copy the dependency management configurations.
this.template('_package.json', 'package.json');
this.template('_bower.json', 'bower.json');
// Copy the CI configurations.
this.template('_travis.yml', '.travis.yml');
// Copy the README and LICESNSE
this.template('_readme.md', 'README.md');
this.template('_license', 'LICENSE');
},
projectfiles: function() {
this.copy('editorconfig', '.editorconfig');
this.copy('coffeelint', '.coffeelint');
this.copy('bowerrc', '.bowerrc');
// Copy server code.
this.template('_server.coffee', 'server.coffee');
// Copy configurations.
this.template('config/_configuration.coffee', 'config/configuration.coffee');
this.copy('config/development.coffee', 'config/development.coffee');
this.copy('config/production.coffee', 'config/production.coffee');
this.copy('config/test.coffee', 'config/test.coffee');
// Copy models.
this.copy('models/index.coffee', 'models/index.coffee');
this.copy('models/todos.coffee', 'models/todos.coffee');
// Copy public.
this.copy('public/favicon.ico', 'public/favicon.ico');
// Copy routes.
this.copy('routes/index.coffee', 'routes/index.coffee');
this.copy('routes/static.coffee', 'routes/static.coffee');
this.copy('routes/v1/todos.coffee', 'routes/v1/todos.coffee');
// Copy spec.
this.copy('spec/specHelper.coffee', 'spec/specHelper.coffee');
this.copy('spec/routes/staticSpec.coffee', 'spec/routes/staticSpec.coffee');
this.copy('spec/routes/v1/todosSpec.coffee', 'spec/routes/v1/todosSpec.coffee');
// Copy views.
this.template('views/_layout.jade', 'views/layout.jade');
this.template('views/_index.jade', 'views/index.jade');
// Copy stylesheets.
this.copy('app/scss/reset/_reset.scss', 'app/scss/reset/_reset.scss');
this.copy('app/scss/reset/_utilities.scss', 'app/scss/reset/_utilities.scss');
this.copy('app/scss/responsive/_screen-responsive-768px.scss', 'app/scss/responsive/_screen-responsive-768px.scss');
this.copy('app/scss/responsive/_screen-responsive-992px.scss', 'app/scss/responsive/_screen-responsive-992px.scss');
this.copy('app/scss/responsive/_screen-responsive-1200px.scss',
'app/scss/responsive/_screen-responsive-1200px.scss');
this.copy('app/scss/ie.scss', 'app/scss/ie.scss');
this.copy('app/scss/print.scss', 'app/scss/print.scss');
this.copy('app/scss/screen.scss', 'app/scss/screen.scss');
// Copy client side MVC.
this.copy('app/coffeescript/controllers/TodoController.coffee',
'app/coffeescript/controllers/TodoController.coffee');
this.copy('app/coffeescript/controllers/TodosController.coffee',
'app/coffeescript/controllers/TodosController.coffee');
this.copy('app/coffeescript/models/Todo.coffee', 'app/coffeescript/models/Todo.coffee');
this.copy('app/coffeescript/routes/TodosActiveRoute.coffee', 'app/coffeescript/routes/TodosActiveRoute.coffee');
this.copy('app/coffeescript/routes/TodosCompletedRoute.coffee',
'app/coffeescript/routes/TodosCompletedRoute.coffee');
this.copy('app/coffeescript/routes/TodosIndexRoute.coffee', 'app/coffeescript/routes/TodosIndexRoute.coffee');
this.copy('app/coffeescript/routes/TodosRoute.coffee', 'app/coffeescript/routes/TodosRoute.coffee');
this.copy('app/coffeescript/views/EditTodoView.coffee', 'app/coffeescript/views/EditTodoView.coffee');
this.copy('app/coffeescript/application.coffee', 'app/coffeescript/application.coffee');
this.copy('app/coffeescript/router.coffee', 'app/coffeescript/router.coffee');
// Copy templates.
this.copy('app/templates/todos.hbs', 'app/templates/todos.hbs');
this.copy('app/templates/todos/index.hbs', 'app/templates/todos/index.hbs');
// Copy models.
this.copy('models/todos.coffee', 'models/todos.coffee');
}
});
module.exports = NodeBoilerplateGenerator;