npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yocrud

v0.1.1

Published

Build fast webapp based on Express

Downloads

7

Readme

YoCrud

It is a yeoman generator to generate automatically code about dao, routes, angular resources, angular controllers, mongoose models.

Installation

First install yeoman

npm install -g yeoman

Then create a Gruntfile.js needed by yeoman to find yocrud

touch Gruntfile.js

Finally install yocrud

npm install yocrud

Usage

You can choose to invoke a single generator among 4 generators: dao, route, angular, model or to invoke them all in series.

If you want to invoke all generatos run

yeoman init yocrud <name>

where <name> is the name of your app.

For example, if you mant an app to handle books, run yeoman init yocrud Book.

Otherwise you can invoke a single generator:

yeoman init yocrud:<name of generator> <name>

where <name of a generator> can be dao, angular, route or model.

Below you can find documentation about the single generators.

Model generator

This generator creates a file that contains model declarations for mongoose. Tipically, if you run yeoman init yocrud:model Book, it generates the file model/Book.js and its content will be:

var mongoose = require('mongoose')
,       Schema = mongoose.Schema
,       DB=require('./DB.js')

function BookSchema=new Schema({},{ strict:false  })

mongoose.model( 'Book' , BookSchema )

function Book(){
        return DB.model( 'Book' )
}

Dao generator

It generates code to query and save a model to MongoDb via mongoose.

If you run yeoman init yocrud:dao Book it will generate the file dao/BookDao.js and its content will be


var Model=require('../model/'+Book+'js')


function BookDao(){}

BookDao.prototype.save(obj, cb){
	var model=new Model(obj)
	model.save(cb)
}

BookDao.prototype.query(query, cb){
	Model.find(query,cb)
}

BookDao.prototype.get(query, cb){
	Model.findOne(query,cb)
}

BookDao.prototype.update(query, update, cb){
	Model.update(query, update,cb)
}

BookDao.prototype.remove(query,cb){
	Model.remove(query,cb)
}

module.exports=BookDao

Route generator

It generates code that consists in http handlers (according to REST style).

If you run yeoman init yocrud:route Book it will generates route/BookRoute.js whose content is:

var ModelDao=require('../dao/'+Book+'Dao.js')

function BookRoute=function(options){
	options.app.get('/'+Book,this.get)
	options.app.get('/'+Book+'/:_id',this.getSingle)
	options.app.put('/'+Book+'/:_id',this.update)
	options.app.post('/'+Book,this.save)	
}

BookRoute.prototype.get=function(req,res,next){
	ModelDao.query(req.query,function(err,docs){
		(err)?res.json(500,err):res.json(200,docs)
		})
}

BookRoute.prototype.getSingle=function(req,res,next){
	ModelDao.query({_id:req.params._id},function(err,doc){
		(err)?res.json(500,err):res.json(200,doc)
	})
}

BookRoute.prototype.remove=function(req,res,next){
	ModelDao.remove(req.body,function(err){
		(err)?res.json(500,err):res.json(200,{success:'ok'})
		})
}

BookRoute.prototype.update=function(req,res,next){
	ModelDao.update(req.body._id,req.body,function(err){
		(err)?res.json(500,err):res.json(200,{success:'ok'})
	})
}

BookRoute.prototype.save=function(req,res,next){
	ModelDao.save(req.body,function(err,doc){
		(err)?res.json(500,err):res.json(200,doc)
	})
}

TODO

  • example app
  • better integration with angular
  • USAGE files
  • generation of a index.html page
  • better integration with bootstrap
  • better README.md