generator-demi
v0.1.6
Published
A Demi.js Generator for Yeoman
Downloads
3
Readme
Demi Generator
A Demi.js Generator for Yeoman.
Getting Started
What is Yeoman?
Trick question. It's not a thing. It's this guy:
Basically, he wears a top hat, lives in your computer, and waits for you to tell him what kind of application you wish to create.
Not every new computer comes with a Yeoman pre-installed. He lives in the npm package repository. You only have to ask for him once, then he packs up and moves into your hard drive. Make sure you clean up, he likes new and shiny things.
$ npm install -g yo
Yeoman Generators
Yeoman travels light. He didn't pack any generators when he moved in. You can think of a generator like a plug-in. You get to choose what type of application you wish to create, such as a Backbone application or even a Chrome extension.
To install generator-demi from npm, run:
$ npm install -g generator-demi
Finally, initiate the generator:
$ yo demi
Generators
Available generators:
Note: Generators are to be run from the root directory of your app.
Controller
Generates a controller in api/controllers
.
Example:
yo demi:controller tasks index:GET show:GET update:PUT destroy:DELETE
Produces api/controllers/tasks.js
:
/*
* demi
* https://github.com/enytc/demi
*
* Copyright (c) 2014 Christopher EnyTC
* Licensed under the MIT license.
*/
'use strict';
module.exports = {
/*
* GET /tasks
*/
/*
* GET /tasks/index
*/
index: {
method: 'GET',
fn: function (req, res) {
//
}
},
/*
* GET /tasks/show
*/
show: {
method: 'GET',
fn: function (req, res) {
//
}
},
/*
* PUT /tasks/update
*/
update: {
method: 'PUT',
fn: function (req, res) {
//
}
},
/*
* DELETE /tasks/destroy
*/
destroy: {
method: 'DELETE',
fn: function (req, res) {
//
}
},
};
Restful
Generates a restful controller in api/controllers
.
Example:
yo demi:restful users
Produces api/controllers/users.js
:
/*
* demi
* https://github.com/enytc/demi
*
* Copyright (c) 2014 Christopher EnyTC
* Licensed under the MIT license.
*/
'use strict';
module.exports = {
/*
* GET /users
*/
index: function (req, res) {
//
},
/*
* GET /users/new
*/
new: function (req, res) {
//
},
/*
* POST /users
*/
create: function (req, res) {
//
},
/*
* GET /users/:task
*/
show: function (req, res) {
//
},
/*
* GET /users/:task/edit
*/
edit: function (req, res) {
//
},
/*
* PUT /users/:task
*/
update: function (req, res) {
//
},
/*
* DELETE /users/:task
*/
destroy: function (req, res) {
//
}
};
Middleware
Generates a middleware in api/middlewares
.
Example:
yo demi:middleware demi_example
Produces api/middlewares/demi_example.js
:
/*
* demi
* https://github.com/enytc/demi
*
* Copyright (c) 2014 Christopher EnyTC
* Licensed under the MIT license.
*/
'use strict';
/*
* Name: demi_example
*/
module.exports = {
/*
* Set true if you want enable this middleware
*/
enabled: true,
fn: function () {
return function (req, res, next) {
//
next();
};
}
};
Model
Generates a model in api/models
.
Example:
yo demi:model Task name:String slug:String closed:Boolean created:Date
Produces api/models/tasks.js
:
/*
* demi
* https://github.com/enytc/demi
*
* Copyright (c) 2014 Christopher EnyTC
* Licensed under the MIT license.
*/
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
/*
* Task Schema
*/
var TaskSchema = new Schema({
name: {
type: String
},
slug: {
type: String
},
closed: {
type: Boolean
},
created: {
type: Date
},
});
//Exports model
module.exports = mongoose.model('Task', TaskSchema);
Service
Generates a service in api/services
.
Example:
yo demi:service names "name:Chris" "name:Bella"
Produces api/services/names.json
:
{
"name": "Chris",
"name": "Bella",
}
Socket
Generates a socket in api/sockets
.
Example:
yo demi:socket test index
Produces api/sockets/test.js
:
/*
* demi
* https://github.com/enytc/demi
*
* Copyright (c) 2014 EnyTC Corporation
* Licensed under the BSD license.
*/
'use strict';
module.exports = {
/*
* SOCKET test/index
*/
index: {
on: function (data) {
console.log(data);
this.emit('test/index', 'testing sockets');
},
emit: 'test this'
},
};
Test
Generates a test in test/
.
Example:
yo demi:make tasks "GET /tasks" "should be return a welcome"
Produces test/tasks_test.js
:
/*
* demi
* https://github.com/enytc/demi
*
* Copyright (c) 2014 Christopher EnyTC
* Licensed under the MIT license.
*/
'use strict';
var supertest = require('supertest');
var demi = require('../lib/demi.js');
var request = supertest(demi());
var chai = require('chai');
chai.expect();
chai.should();
describe('#tasks', function () {
describe('GET /tasks', function () {
it('should be return a welcome', function (done) {
request
.get('/tasks')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, {}, done);
});
});
});
Getting To Know Yeoman
Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced.
If you'd like to get to know Yeoman better and meet some of his friends, Grunt and Bower, check out the complete Getting Started Guide.
Contributing
See the CONTRIBUTING Guidelines
Support
If you have any problem or suggestion please open an issue here.
License
Copyright (c) 2014 Christopher EnyTC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.