generator-vile

0.2.2 • Public • Published

generator-vile Build Status

Yeoman generator that goes beyond the MEAN stack. Uses MongoDB, Express, Angular, and Stylus and is configured for easy deployment to Heroku. Enables easier directory system by calling subgenerators with groups.

Usage

Install generator-vile:

npm install -g generator-vile

Make a new directory and cd into it:

mkdir new-project && cd $_

run yo vile

yo vile

Run grunt to build and grunt server to start local server.

All generators (except model) are called using the following syntax: [group:[subgroup1:subgroup2...]]:name This will generate the given files inside the group folder if given. Subgroups are created inside the generators type folder. For example:

yo vile:service games:entities:shapes:ball

Will create app/scripts/games/services/entities/shape/ball.js. This allows subgrouping within a general angular type.

Available generators:

App

Sets up a new AngularJS app using the MEAN stack. Automatically links to Twitter Bootstrap via CDN.

Example:

yo vile

Route

Generates a controller and view within an optional group folder. Configures a route in app/scripts/app.js connecting them.

Example:

yo angular:route posts:show

Produces app/scripts/posts/show.js:

angular.module('myApp').controller('ShowCtrl', function ($scope) {
  $scope.foo = 'foo';
});

Produces app/views/posts/show.html:

<p>This is the Posts:Show view</p>

Model

Generates a Mongoose document with given parameters. Adds RESTful backend routes to Express server. RESTful ID defaults to name property if exists, else uses _id. Can be overridden by --identifier option. Generates Angular $resource for frontend. Use : to attach types to property, default is String.

Example:

yo vile:model post name description date:date ranking:number

Produces db/post.js

//... Dependencies

var PostSchema = new Schema({
  name: String,
  description: String,
  date: Date,
  ranking: Number,
  urlString: String
});

PostSchema.pre('save', function (next) {
  if (this.name) {
    this.urlString = this.name.toLocaleLowerCase().replace(/\s+/g, '-');
  }
  next();
});

mongoose.model('Post', PostSchema);

Produces routes/posts.js:

var mongoose = require('mongoose');

module.exports = function (app) {
  var Post = mongoose.model('Post');

  // GET /posts => Index
  app.get('/posts', function (req, res) {
    Post.find()
      .exec(function (err, posts) {
        if (err) { console.log(err); }
        res.send(posts);
      });
  });

  // GET /posts/id => Show
  app.get('/posts/:id', function (req, res) {
    Post.findOne({urlString: req.params.id})
      .exec(function (err, post) {
        if (err) { console.log(err); }
        res.send(post);
      });
  });

  // DEL /posts/id => Remove
  app.del('/posts/:id', function (req, res) {
    Post.findOneAndRemove({urlString: req.params.id}, function (err, post) {
      if (err) { console.log(err); }
      res.send(post);
    });
  });

  // POST /posts => Create
  app.post('/posts', function (req, res) {
    var post = new Post(req.body);
    post.save(function (err) {
      if (err) { console.log(err); }
      res.send(post);
    });
  });

  // PUT /posts/id => Update
  app.put('/posts', function (req, res) {
    Post.findOne({urlString: req.params.id}, function (err, post) {
      if (err) {console.log(err);}
      
      post.name = req.body.name;
      
      post.description = req.body.description;
      
      post.date = req.body.date;
      
      post.ranking = req.body.ranking;
      
      post.save(function (err) {
        if (err) { console.log(err); }
        res.send(post);
      });
    });
  });

};

Controller

Generates a controller file within an optional group folder

Example:

yo vile:controller posts:new

Produces app/scripts/posts/controllers/new.js:

angular.module('myApp').controller('NewCtrl', function ($scope) {
  // ...
});

Directive

Generates a directive file within an optional group folder Add --template to use a seperate template file created in app/templates

Example:

yo vile:directive posts:details

Produces app/scripts/posts/directives/details.js:

angular.module('myApp').directive('details', function () {

  return {
   template: '<div></div>',
   restrict: 'E',
   link: function postLink(scope, element, attrs) {
    element.text('this is the details directive');
   }
  };
});

Filter

Generates a filter within an optional group folder

Example:

yo vile:filter groupBy

Produces app/scripts/filters/groupBy.js:

angular.module(myApp).filter('groupBy', function () {
  return function (input) {
    return 'groupBy filter:' + input;
  };
});

View

Generates an HTML view file within an optional group folder

Example:

yo vile:view posts:new

Produces app/views/posts/new.html:

<p>This is the Page:View page</p>

Service

Generates an AngularJS service within an optional group folder.

Example:

yo vile:service myService

Produces app/scripts/services/myService.js:

angular.module('myApp').service('myService', function () {
  // ...
});

Factory

Generates an AngularJS factory within an optional group folder.

Example:

yo vile:factory factoryName

Produces app/scripts/services/factoryName.js:

angular.module('myApp')
  .factory('factoryName', function () {
  // ...
  });

Class

Generates an AngularJS class within an optional group folder.

Example:

yo vile:class games:renderer

Produces app/scripts/games/services/renderer:

angular.module('myApp')
  .factory('Renderer', function () {
    var Renderer = function () {

    };

    return Renderer;
  });

Add to Index

By default, new scripts are added to index.html. To skip this behaviour, pass in the skip-add argument:

yo vile:service serviceName --skip-add

Bower Components

The app generator always installs these packages:

  • jQuery
  • angular
  • angular-resource
  • angular-route
  • angular-cookies
  • angular-sanitzie
  • angular-mocks
  • angular-scenario

License

MIT License

Readme

Keywords

Package Sidebar

Install

npm i generator-vile

Weekly Downloads

19

Version

0.2.2

License

none

Last publish

Collaborators

  • amctammany