Skip to content

Commit 8e88a5d

Browse files
author
Robert Yokota
committed
First commit
0 parents  commit 8e88a5d

35 files changed

+1169
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
temp/

.jshintrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"node": true,
3+
"esnext": true,
4+
"bitwise": true,
5+
"camelcase": true,
6+
"curly": true,
7+
"eqeqeq": true,
8+
"immed": true,
9+
"indent": 4,
10+
"latedef": true,
11+
"newcap": true,
12+
"noarg": true,
13+
"quotmark": "single",
14+
"regexp": true,
15+
"undef": true,
16+
"unused": true,
17+
"strict": true,
18+
"trailing": true,
19+
"smarttabs": true,
20+
"white": true
21+
}

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
node_js:
3+
- '0.10'
4+
- '0.8'
5+
before_install:
6+
- currentfolder=${PWD##*/}
7+
- if [ "$currentfolder" != 'generator-angular-express-sequelize' ]; then cd .. && eval "mv $currentfolder generator-angular-express-sequelize" && cd generator-angular-express-sequelize; fi
8+

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2013 Robert Yokota
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# The Angular-Express-Sequelize generator
2+
3+
A [Yeoman](http://yeoman.io) generator for [AngularJS](http://angularjs.org) and [Express](http://expressjs.com) with [Sequelize](http://sequelizejs.com).
4+
5+
## Installation
6+
7+
Install [Git](http://git-scm.com), [node.js](http://nodejs.org), and [Ruby](https://www.ruby-lang.org/). The development mode also requires [SQLite](http://www.sqlite.org).
8+
9+
Install Yeoman:
10+
11+
npm install -g yo
12+
13+
Install the Angular-Express-Sequelize generator:
14+
15+
npm install -g generator-angular-express-sequelize
16+
17+
## Creating an Express service
18+
19+
In a new directory, generate the service:
20+
21+
yo angular-express-sequelize
22+
23+
Run the service:
24+
25+
rackup
26+
27+
Your service will run at [http://localhost:9292](http://localhost:9292).
28+
29+
30+
## Creating a persistent entity
31+
32+
Generate the entity:
33+
34+
yo angular-express-sequelize:entity [myentity]
35+
36+
You will be asked to specify attributes for the entity, where each attribute has the following:
37+
38+
- a name
39+
- a type (String, Integer, Float, Boolean, Date, Enum)
40+
- for a String attribute, an optional minimum and maximum length
41+
- for a numeric attribute, an optional minimum and maximum value
42+
- for a Date attribute, an optional constraint to either past values or future values
43+
- for an Enum attribute, a list of enumerated values
44+
- whether the attribute is required
45+
46+
Run the service:
47+
48+
rackup
49+
50+
A client-side AngularJS application will now be available by running
51+
52+
grunt server
53+
54+
The Grunt server will run at [http://localhost:9000](http://localhost:9000). It will proxy REST requests to the Express service running at [http://localhost:3000](http://localhost:3000).
55+
56+
At this point you should be able to navigate to a page to manage your persistent entities.
57+
58+
The Grunt server supports hot reloading of client-side HTML/CSS/Javascript file changes.
59+

app/index.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'use strict';
2+
var util = require('util'),
3+
path = require('path'),
4+
yeoman = require('yeoman-generator'),
5+
_ = require('lodash'),
6+
_s = require('underscore.string'),
7+
pluralize = require('pluralize'),
8+
asciify = require('asciify');
9+
10+
var AngularExpressSequelizeGenerator = module.exports = function AngularExpressSequelizeGenerator(args, options, config) {
11+
yeoman.generators.Base.apply(this, arguments);
12+
13+
this.on('end', function () {
14+
this.installDependencies({ skipInstall: options['skip-install'] });
15+
if (!options['skip-install']) {
16+
return this.spawnCommand('bundle', ['install']);
17+
}
18+
});
19+
20+
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
21+
};
22+
23+
util.inherits(AngularExpressSequelizeGenerator, yeoman.generators.Base);
24+
25+
AngularExpressSequelizeGenerator.prototype.askFor = function askFor() {
26+
27+
var cb = this.async();
28+
29+
console.log('\n' +
30+
'+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+\n' +
31+
'|a|n|g|u|l|a|r| |e|x|p|r|e|s|s| |s|e|q|u|e|l|i|z|e| |g|e|n|e|r|a|t|o|r|\n' +
32+
'+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+\n' +
33+
'\n');
34+
35+
var prompts = [{
36+
type: 'input',
37+
name: 'baseName',
38+
message: 'What is the name of your application?',
39+
default: 'myapp'
40+
}];
41+
42+
this.prompt(prompts, function (props) {
43+
this.baseName = props.baseName;
44+
45+
cb();
46+
}.bind(this));
47+
};
48+
49+
AngularExpressSequelizeGenerator.prototype.app = function app() {
50+
51+
this.copy('gitignore', '.gitignore');
52+
this.entities = [];
53+
this.resources = [];
54+
this.generatorConfig = {
55+
"baseName": this.baseName,
56+
"entities": this.entities,
57+
"resources": this.resources
58+
};
59+
this.generatorConfigStr = JSON.stringify(this.generatorConfig, null, '\t');
60+
61+
this.template('_generator.json', 'generator.json');
62+
this.template('_package.json', 'package.json');
63+
this.template('_bower.json', 'bower.json');
64+
this.template('bowerrc', '.bowerrc');
65+
this.template('Gruntfile.js', 'Gruntfile.js');
66+
this.copy('gitignore', '.gitignore');
67+
68+
var modelsDir = 'models/'
69+
var publicDir = 'public/'
70+
var routesDir = 'routes/'
71+
var viewsDir = 'views/'
72+
this.mkdir(modelsDir);
73+
this.mkdir(publicDir);
74+
this.mkdir(routesDir);
75+
this.mkdir(viewsDir);
76+
77+
this.template('_app.js', 'app.js');
78+
this.template('models/_index.js', modelsDir + 'index.js');
79+
80+
var publicCssDir = publicDir + 'css/';
81+
var publicJsDir = publicDir + 'js/';
82+
var publicViewDir = publicDir + 'views/';
83+
this.mkdir(publicCssDir);
84+
this.mkdir(publicJsDir);
85+
this.mkdir(publicViewDir);
86+
this.template('public/_index.html', publicDir + 'index.html');
87+
this.copy('public/css/app.css', publicCssDir + 'app.css');
88+
this.template('public/js/_app.js', publicJsDir + 'app.js');
89+
this.template('public/js/home/_home-controller.js', publicJsDir + 'home/home-controller.js');
90+
this.template('public/views/home/_home.html', publicViewDir + 'home/home.html');
91+
};
92+
93+
AngularExpressSequelizeGenerator.prototype.projectfiles = function projectfiles() {
94+
this.copy('editorconfig', '.editorconfig');
95+
this.copy('jshintrc', '.jshintrc');
96+
};

app/templates/Gruntfile.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
'use strict';
2+
3+
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
4+
5+
module.exports = function (grunt) {
6+
require('load-grunt-tasks')(grunt);
7+
require('time-grunt')(grunt);
8+
9+
grunt.initConfig({
10+
yeoman: {
11+
// configurable paths
12+
app: require('./bower.json').appPath || 'public',
13+
dist: 'public'
14+
},
15+
sync: {
16+
dist: {
17+
files: [{
18+
cwd: '<%%= yeoman.app %>',
19+
dest: '<%%= yeoman.dist %>',
20+
src: '**'
21+
}]
22+
}
23+
},
24+
watch: {
25+
options: {
26+
livereload: 35729
27+
},
28+
src: {
29+
files: [
30+
'<%%= yeoman.app %>/*.html',
31+
'<%%= yeoman.app %>/css/**/*',
32+
'<%%= yeoman.app %>/js/**/*',
33+
'<%%= yeoman.app %>/views/**/*'
34+
],
35+
//tasks: ['sync:dist']
36+
}
37+
},
38+
connect: {
39+
proxies: [
40+
{
41+
context: '/<%= baseName %>',
42+
host: 'localhost',
43+
port: 3000,
44+
https: false,
45+
changeOrigin: false
46+
}
47+
],
48+
options: {
49+
port: 9000,
50+
// Change this to '0.0.0.0' to access the server from outside.
51+
hostname: 'localhost',
52+
livereload: 35729
53+
},
54+
livereload: {
55+
options: {
56+
open: true,
57+
base: [
58+
'<%%= yeoman.app %>'
59+
],
60+
middleware: function (connect) {
61+
return [
62+
proxySnippet,
63+
connect.static(require('path').resolve('public'))
64+
];
65+
}
66+
}
67+
},
68+
/*
69+
dist: {
70+
options: {
71+
base: '<%%= yeoman.dist %>'
72+
}
73+
}
74+
*/
75+
},
76+
// Put files not handled in other tasks here
77+
copy: {
78+
dist: {
79+
files: [{
80+
expand: true,
81+
dot: true,
82+
cwd: '<%%= yeoman.app %>',
83+
dest: '<%%= yeoman.dist %>',
84+
src: '**'
85+
}]
86+
},
87+
},
88+
// Test settings
89+
karma: {
90+
unit: {
91+
configFile: 'test/config/karma.conf.js',
92+
singleRun: true
93+
}
94+
},
95+
bowercopy: {
96+
options: {
97+
destPrefix: '<%%= yeoman.app %>'
98+
},
99+
test: {
100+
files: {
101+
'test/lib/angular-mocks': 'angular-mocks',
102+
'test/lib/angular-scenario': 'angular-scenario'
103+
}
104+
}
105+
}
106+
});
107+
108+
grunt.registerTask('server', function (target) {
109+
grunt.task.run([
110+
//'copy:dist',
111+
'configureProxies',
112+
'connect:livereload',
113+
'watch'
114+
]);
115+
});
116+
};

app/templates/README.md.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Overview
2+
3+
Blah blah
4+

app/templates/_app.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var express = require('express')
2+
<% _.each(entities, function (entity) { %>
3+
, <%= pluralize(entity.name) %> = require('./routes/<%= pluralize(entity.name) %>')<% }); %>
4+
, http = require('http')
5+
, path = require('path')
6+
, db = require('./models')
7+
8+
var app = express()
9+
10+
// all environments
11+
app.set('port', process.env.PORT || 3000)
12+
app.set('views', __dirname + '/views')
13+
app.set('view engine', 'jade')
14+
app.use(express.favicon())
15+
app.use(express.logger('dev'))
16+
app.use(express.json())
17+
app.use(express.urlencoded())
18+
app.use(express.methodOverride())
19+
app.use(app.router)
20+
app.use(express.static(path.join(__dirname, 'public')))
21+
22+
// development only
23+
if ('development' === app.get('env')) {
24+
app.use(express.errorHandler())
25+
}
26+
27+
<% _.each(entities, function (entity) { %>
28+
app.get('/<%= baseName %>/<%= pluralize(entity.name) %>', <%= pluralize(entity.name) %>.findAll)
29+
app.get('/<%= baseName %>/<%= pluralize(entity.name) %>/:id', <%= pluralize(entity.name) %>.find)
30+
app.post('/<%= baseName %>/<%= pluralize(entity.name) %>', <%= pluralize(entity.name) %>.create)
31+
app.put('/<%= baseName %>/<%= pluralize(entity.name) %>/:id', <%= pluralize(entity.name) %>.update)
32+
app.delete('/<%= baseName %>/<%= pluralize(entity.name) %>/:id', <%= pluralize(entity.name) %>.destroy)
33+
<% }); %>
34+
35+
db
36+
.sequelize
37+
.sync()
38+
.complete(function(err) {
39+
if (err) {
40+
throw err
41+
} else {
42+
http.createServer(app).listen(app.get('port'), function(){
43+
console.log('Express server listening on port ' + app.get('port'))
44+
})
45+
}
46+
})

0 commit comments

Comments
 (0)