Initial commit with support for modules and services

This commit is contained in:
molant 2015-05-22 16:18:05 -07:00
Коммит c6469b1ae2
20 изменённых файлов: 517 добавлений и 0 удалений

12
.editorconfig Normal file
Просмотреть файл

@ -0,0 +1,12 @@
# http://editorconfig.org
root = true
[*]
indent_style = tab
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
[*.md]
trim_trailing_whitespace = false

149
.eslintrc Normal file
Просмотреть файл

@ -0,0 +1,149 @@
{
"env": {
"browser": false,
"node": true,
"amd": false,
"mocha": true,
"jasmine": false
},
"rules": {
"no-alert": 2,
"no-array-constructor": 2,
"no-bitwise": 0,
"no-caller": 2,
"no-catch-shadow": 2,
"no-cond-assign": 2,
"no-console": 0,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-div-regex": 0,
"no-dupe-keys": 2,
"no-else-return": 0,
"no-empty": 2,
"no-empty-class": 2,
"no-empty-label": 2,
"no-eq-null": 0,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-fallthrough": 2,
"no-floating-decimal": 0,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inline-comments": 0,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 0,
"no-loop-func": 2,
"no-mixed-requires": [0, false],
"no-mixed-spaces-and-tabs": [2, false],
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [0, {"max": 2}],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-nested-ternary": 0,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 0,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 0,
"no-plusplus": 0,
"no-process-env": 0,
"no-process-exit": 2,
"no-proto": 2,
"no-redeclare": 0,
"no-regex-spaces": 2,
"no-reserved-keys": 0,
"no-restricted-modules": 0,
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 0,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-sync": 0,
"no-ternary": 0,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-undefined": 2,
"no-underscore-dangle": 0,
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
"no-use-before-define": 2,
"no-void": 0,
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
"no-with": 2,
"no-wrap-func": 2,
"block-scoped-var": 0,
"brace-style": [0, "1tbs"],
"camelcase": 0,
"comma-spacing": 2,
"comma-style": 0,
"comma-dangle": [2, "never"],
"complexity": [0, 11],
"consistent-return": 2,
"consistent-this": [0, "that"],
"curly": [2, "all"],
"default-case": 0,
"dot-notation": 2,
"eol-last": 0,
"eqeqeq": 2,
"func-names": 0,
"func-style": [2, "expression"],
"guard-for-in": 0,
"handle-callback-err": 0,
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"max-depth": [0, 4],
"max-len": [0, 80, 4],
"max-nested-callbacks": [0, 2],
"max-params": [0, 3],
"max-statements": [0, 10],
"new-cap": 2,
"new-parens": 2,
"one-var": 0,
"operator-assignment": [0, "always"],
"padded-blocks": 0,
"quote-props": 0,
"quotes": [2, "single"],
"radix": 0,
"semi": 2,
"sort-vars": 0,
"space-after-keywords": [0, "always"],
"space-before-blocks": [0, "always"],
"space-in-brackets": [0, "never"],
"space-in-parens": [0, "never"],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-line-comment": [0, "always"],
"strict": [2, "global"],
"use-isnan": 2,
"valid-jsdoc": 0,
"valid-typeof": 2,
"vars-on-top": 0,
"wrap-iife": [2, "outside"],
"wrap-regex": 0,
"yoda": [2, "never"]
}
}

1
.gitattributes поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
* text=auto

2
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,2 @@
node_modules/
/.settings/

6
.travis.yml Normal file
Просмотреть файл

@ -0,0 +1,6 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'

3
.yo-rc.json Normal file
Просмотреть файл

@ -0,0 +1,3 @@
{
"generator-generator": {}
}

51
README.md Normal file
Просмотреть файл

@ -0,0 +1,51 @@
# generator-lasagnajs
> [Yeoman](http://yeoman.io) generator
## Getting Started
This demo generator allows you to easily create modules and services for the lasagnajs architecture.
### What is Yeoman?
Trick question. It's not a thing. It's this guy:
![](http://i.imgur.com/JHaAlBJ.png)
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](https://npmjs.org) 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.*
```bash
npm install -g yo
```
### About this 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-lasagnajs from npm, run:
```bash
npm install -g generator-lasagnajs
```
At the moment only subgenerators for modules and services are supported:
```bash
yo lasagnaJS:module modulename
yo lasagnaJS:service servicename
```
### 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](http://gruntjs.com) and [Bower](http://bower.io), check out the complete [Getting Started Guide](https://github.com/yeoman/yeoman/wiki/Getting-Started).
## License
MIT

Просмотреть файл

@ -0,0 +1,65 @@
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
module.exports = yeoman.generators.NamedBase.extend({
prompting: function () {
var done = this.async();
// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the ' + chalk.red('CalimeroJS') + ' generator for modules!'
));
var prompts = [{
type: 'confirm',
name: 'async',
message: 'Would you like to make your module async?',
default: true
}];
this.prompt(prompts, function (props) {
this.props = props;
// To access props later use this.props.someOption;
done();
}.bind(this));
},
writing: function () {
console.log(this.name);
var name = this.name;
var async = this.props.async;
var context = {
name: name,
async: async
};
var destination = 'modules/' + name + '/';
var files = ['routes/admin.js',
'routes/api.js',
'routes/base.js',
'index.js'];
var filesToRename = ['public/scripts/index.js',
'public/styles/index.css',
'views/index.handlebars',
'views/index-admin.handlebars'];
for (var i = 0; i < files.length; i++) {
this.fs.copyTpl(
this.templatePath(files[i]),
this.destinationPath(destination + files[i]),
context);
}
for (var i = 0; i < filesToRename.length; i++) {
this.fs.copyTpl(
this.templatePath(filesToRename[i]),
this.destinationPath((destination + filesToRename[i]).replace('index', name)),
context);
}
}
});

Просмотреть файл

@ -0,0 +1,18 @@
'use strict';
module.exports = {
init: function (Router, configurator, lodash, logger) {
var that = this;
var router = new Router({
adminRoutes: require('./routes/admin.js')(configurator, lodash, logger),
apiRoutes: require('./routes/api.js')(configurator, lodash, logger),
baseRoutes: require('./routes/base.js')(configurator, lodash, logger),
name: that.name
});
return router;
},
name: '<%= name %>',
async: <%= async %>
};

Просмотреть файл

@ -0,0 +1,5 @@
/* eslint-env browser*/
(function () {
'use strict';
//This is the script for your module
}());

Просмотреть файл

@ -0,0 +1 @@
/* The CSS for your module */

Просмотреть файл

@ -0,0 +1,16 @@
'use strict';
var adminRoutes = function (configurator, _, logger) {
return function (router) {
logger.log('<%= name %> admin routes set');
var renderHome = function (req, res) {
res.render('<%= name %>-admin', {
layout: 'admin'
});
};
router.get('/', renderHome);
};
};
module.exports = adminRoutes;

Просмотреть файл

@ -0,0 +1,15 @@
'use strict';
var apiRoutes = function (configurator, _, logger) {
return function (router) {
logger.log('<%= name %> api routes set');
var sendOK = function(req, res){
res.send('OK');
};
router.get('/', sendOK);
};
};
module.exports = apiRoutes;

Просмотреть файл

@ -0,0 +1,19 @@
'use strict';
var baseRoutes = function (configurator, _, logger) {
return function (router) {
logger.log('<%= name %> public routes set');
var renderHomePage = function(req, res){
res.render('<%= name %>', {
header: {
module: ''
}
});
};
router.get('/', renderHomePage);
};
};
module.exports = baseRoutes;

Просмотреть файл

@ -0,0 +1,3 @@
<div class="content">
Admin section!
</div>

Просмотреть файл

@ -0,0 +1,30 @@
{{#section 'css'}}
<!-- build:css /styles/<%= name %>.css -->
<link rel="stylesheet" href="/styles/<%= name %>.css"/>
<!-- endbuild -->
{{/section}}
{{#section 'js'}}
<!-- build:js /styles/<%= name %>.js -->
<script src="/scripts/<%= name %>.js" defer></script>
<!-- endbuild -->
{{/section}}
<main role="main" class="content">
<section role="region" class="section">
<div class="container">
<header class="section__header">
<h2 class="title">This is a header</a></h2>
</header>
<div class="section__body">
<div class="layout layout--basic">
<div class="module module--secondary">
This is some secondary content
</div>
<div class="module module--primary">
This is the primary content
</div>
</div>
</div>
</div>
</section>
</main>

Просмотреть файл

@ -0,0 +1,49 @@
'use strict';
var chalk = require('chalk');
var yeoman = require('yeoman-generator');
var yosay = require('yosay');
module.exports = yeoman.generators.NamedBase.extend({
prompting: function () {
var done = this.async();
// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the ' + chalk.red('CalimeroJS') + ' generator for services!'
));
var prompts = [{
type: 'confirm',
name: 'async',
message: 'Would you like to make your service async?',
default: true
}];
this.prompt(prompts, function (props) {
this.props = props;
// To access props later use this.props.someOption;
done();
}.bind(this));
},
writing: function () {
console.log(this.name);
var name = this.name;
var async = this.props.async;
var context = {
name: name,
async: async
};
var destination = 'services/' + name + '/';
var files = ['index.js'];
for (var i = 0; i < files.length; i++) {
this.fs.copyTpl(
this.templatePath(files[i]),
this.destinationPath(destination + files[i]),
context);
}
}
});

Просмотреть файл

@ -0,0 +1,18 @@
'use strict';
var init = function (configurator, logger) {
logger.log('<%= name %> initialized');
var foo = function () {
logger.log('foo called');
};
return {
foo: foo
};
};
module.exports = {
init: init,
name: '<%= name %>',
async: <%= async %>
};

30
package.json Normal file
Просмотреть файл

@ -0,0 +1,30 @@
{
"name": "generator-lasagnajs",
"version": "0.1.0",
"description": "Yeoman generator for lasagnajs architectures",
"license": "MIT",
"main": "app/index.js",
"repository": "MicrosoftEdge/generator-lasagnajs",
"author": {
"name": "Anton Molleda",
"email": "",
"url": "https://github.com/molant"
},
"scripts": {
"test": "mocha"
},
"files": [
"generators"
],
"keywords": [
"yeoman-generator"
],
"dependencies": {
"yeoman-generator": "^0.19.0",
"chalk": "^1.0.0",
"yosay": "^1.0.2"
},
"devDependencies": {
"mocha": "*"
}
}

24
test/test-app.js Normal file
Просмотреть файл

@ -0,0 +1,24 @@
'use strict';
var path = require('path');
var assert = require('yeoman-generator').assert;
var helpers = require('yeoman-generator').test;
var os = require('os');
describe('CalimeroJS:app', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
.withOptions({ skipInstall: true })
.withPrompts({ someOption: true })
.on('end', done);
});
it('creates files', function () {
assert.file([
'bower.json',
'package.json',
'.editorconfig',
'.jshintrc'
]);
});
});