generator-selena

A Selena.js Generator for Yeoman.

Usage no npm install needed!

<script type="module">
  import generatorSelena from 'https://cdn.skypack.dev/generator-selena';
</script>

README

Selena Generator Build Status NPM version Bitdeli Badge

A Selena.js Generator for Yeoman.

Getting Started

What is Yeoman?

Trick question. It's not a thing. It's this guy:

Selena.js

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-selena from npm, run:

$ npm install -g generator-selena

Finally, initiate the generator:

$ yo selena

Generators

Available generators:

Note: Generators are to be run from the root directory of your app.

Route

Generates a controller in app/controllers and generates a view in app/views.

Example:

yo selena:route tasks index:GET show:GET update:PUT destroy:DELETE

Produces app/controllers/tasks.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * 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) {
   //
  }
 },


};

Produces app/views/tasks.html:

{% extends '../layouts/default.html' %} 

{% block content %}
<p>This is the tasks view</p>
{% endblock %}

Controller

Generates a controller in app/controllers.

Example:

yo selena:controller tasks index:GET show:GET update:PUT destroy:DELETE

Produces app/controllers/tasks.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * 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 app/controllers.

Example:

yo selena:restful users

Produces app/controllers/users.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * 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 app/middlewares.

Example:

yo selena:middleware selena_example

Produces app/middlewares/selena_example.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * Copyright (c) 2014 Christopher EnyTC
 * Licensed under the MIT license.
 */

'use strict';

/*
* Name: selena_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 app/models.

Example:

yo selena:model Task name:String slug:String closed:Boolean created:Date

Produces app/models/tasks.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * 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);

View

Generates a view in app/views.

Example:

yo selena:view tasks

Produces app/views/tasks.html:

{% extends '../layouts/default.html' %} 

{% block content %}
<p>This is the tasks view</p>
{% endblock %}

Service

Generates a service in app/services.

Example:

yo selena:service names "name:Chris" "name:Bella"

Produces app/services/names.json:

{
 "name": "Chris",
 "name": "Bella",
}

Socket

Generates a socket in app/sockets.

Example:

yo selena:socket test index

Produces app/sockets/test.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * 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 selena:make tasks "GET /tasks" "should be return a welcome"

Produces test/tasks_test.js:

/*
 * selena
 * https://github.com/enytc/selena
 *
 * Copyright (c) 2014 Christopher EnyTC
 * Licensed under the MIT license.
 */

'use strict';

var supertest = require('supertest');
var selena = require('../lib/selena.js');
var request = supertest(selena().http);
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);
    });
  });
});

ng-route

Generates a controller and view, and configures a route in app/public/app.js connecting them.

Example:

yo selena:ng-route myroute

Produces app/public/controllers/myroute.js:

app.controller('myrouteCtrl', function ($scope) {
  // ...
});

Produces app/public/views/myroute.html:

<p>This is the myroute view</p>

ng-controller

Generates a controller in app/public/controllers.

Example:

yo selena:ng-controller user

Produces app/public/controllers/userCtrl.js:

app.controller('userCtrl', function ($scope) {
  // ...
});

ng-directive

Generates a directive in app/public/directives.

Example:

yo selena:ng-directive myDirective

Produces app/public/directives/myDirective.js:

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

ng-filter

Generates a filter in app/public/filters.

Example:

yo selena:ng-filter myFilter

Produces app/public/filters/myFilter.js:

app.filter('myFilter', function () {
  return function (input) {
    return 'myFilter filter:' + input;
  };
});

ng-view

Generates an HTML view file in app/public/views.

Example:

yo selena:ng-view user

Produces app/public/views/user.html:

<p>This is the user view</p>

ng-service

Generates an AngularJS service.

Example:

yo selena:ng-service myService

Produces app/public/services/myServiceService.js:

app.service('myService', function () {
  // ...
});

You can also do yo selena:ng-factory, yo selena:ng-provider, yo selena:ng-value, and yo selena:ng-constant for other types of services.

ng-decorator

Generates an AngularJS service decorator.

Example:

yo selena:ng-decorator serviceName

Produces app/public/decorators/serviceName.js:

app.config(function ($provide) {
    $provide.decorator('serviceName', function ($delegate) {
      // ...
      return $delegate;
    });
  });

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.