Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from feathersjs/feathers-2.0
Browse files Browse the repository at this point in the history
Feathers 2.0
  • Loading branch information
ekryski committed Jan 13, 2016
2 parents 4de77a0 + 7f6119c commit 1d7cad9
Show file tree
Hide file tree
Showing 41 changed files with 755 additions and 103 deletions.
326 changes: 294 additions & 32 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var generators = require('yeoman-generator');
var path = require('path');
var crypto = require('crypto');
var _ = require('lodash');

module.exports = generators.Base.extend({
Expand All @@ -10,26 +11,137 @@ module.exports = generators.Base.extend({
this.props = {
name: process.cwd().split(path.sep).pop()
};
this.dotfiles = ['editorconfig', 'gitignore', 'jshintrc', 'npmignore', 'travis.yml'];
this.files = ['package.json', 'src/index.js', 'test/index.test.js', 'LICENSE', 'README.md'];
},

prompting: function () {
var done = this.async();
var prompts = [{
name: 'name',
message: 'Project name',
when: !this.pkg.name,
default: this.props.name
}, {
name: 'repository',
message: 'The GitHub repository URL (e.g. feathersjs/feathers-myplugin)',
default: 'feathersjs/' + this.props.name
}, {
name: 'description',
message: 'Description',
when: !this.pkg.description
}];
var prompts = [
{
name: 'name',
message: 'Project name',
when: !this.pkg.name,
default: this.props.name
},
{
name: 'description',
message: 'Description',
when: !this.pkg.description
},
{
type: 'checkbox',
name: 'providers',
message: 'What type of API are you making?',
choices: [
{
name: 'REST',
value: 'rest',
checked: true
},
{
name: 'Realtime via Socket.io',
value: 'socket.io',
checked: true
},
{
name: 'Realtime via Primus',
value: 'primus',
}
]
},
{
type: 'list',
name: 'cors',
message: 'CORS configuration',
choices: [
{
name: 'Enabled for all domains',
value: 'enabled',
checked: true
},
{
name: 'Enabled for whitelisted domains',
value: 'whitelisted'
},
{
name: 'Disabled',
value: false
}
]
},
{
type: 'input',
name: 'corsWhitelist',
message: 'Comma-separated domains for CORS whitelist. Include http(s)',
when: function(props){
return props.cors === 'whitelisted';
}
},
{
type: 'list',
name: 'database',
message: 'What database do you primarily want to use?',
choices: [
{
name: 'I will choose my own',
checked: true
},
{
name: 'Memory',
value: 'memory'
},
{
name: 'MongoDB',
value: 'mongodb'
},
{
name: 'MySQL',
value: 'mysql'
},
{
name: 'MariaDB',
value: 'mariadb'
},
{
name: 'NeDB',
value: 'nedb'
},
{
name: 'PostgreSQL',
value: 'postgres'
},
{
name: 'SQLite',
value: 'sqlite'
},
{
name: 'SQL Server',
value: 'mssql'
}
]
},
{
type: 'checkbox',
name: 'authentication',
message: 'What authentication methods would you like to support?',
choices: [
{
name: 'local',
checked: true
}
// name: 'basic'
// }, {

// }, {
// name: 'google'
// }, {
// name: 'facebook'
// }, {
// name: 'twitter'
// }, {
// name: 'github'
]
}
];

this.prompt(prompts, function (props) {
this.props = _.extend(this.props, props);
Expand All @@ -39,27 +151,177 @@ module.exports = generators.Base.extend({
},

writing: function () {
this.dotfiles.forEach(function(file) {
this.fs.copyTpl(
this.templatePath(file),
this.destinationPath('.' + file),
this.props
);
}.bind(this));
this.props.secret = crypto.randomBytes(64).toString('base64');
this.props.corsWhitelist = this.props.corsWhitelist && this.props.corsWhitelist.split(',');
var dependencies = [
'[email protected]',
'[email protected]',
'feathers-configuration',
'serve-favicon',
'compression',
'winston',
'babel-core',
'babel-preset-es2015'
];

this.files.forEach(function(file) {
this.fs.copyTpl(
this.templatePath(file),
this.destinationPath(file),
this.props
);
}.bind(this));
if (this.props.providers.indexOf('rest') !== -1) {
dependencies.push('body-parser');
dependencies.push('feathers-rest');
}

if (this.props.providers.indexOf('socket.io') !== -1) {
dependencies.push('feathers-socketio');
}

if (this.props.providers.indexOf('primus') !== -1) {
dependencies.push('feathers-primus');
}

if (this.props.authentication.length) {
dependencies.push('feathers-authentication');
}

if (this.props.cors) {
dependencies.push('cors');
}

switch(this.props.database) {
case 'memory':
dependencies.push('feathers-memory');
this.fs.copyTpl(
this.templatePath('services/memory-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
case 'mongodb':
dependencies.push('mongoose');
dependencies.push('feathers-mongoose');
this.fs.copyTpl(
this.templatePath('models/mongoose-user.js'),
this.destinationPath('server/models', 'user.js'),
this.props
);
this.fs.copyTpl(
this.templatePath('services/mongoose-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
case 'mysql':
case 'mariadb':
dependencies.push('mysql');
dependencies.push('sequelize');
dependencies.push('feathers-sequelize');
this.fs.copyTpl(
this.templatePath('models/sequelize-user.js'),
this.destinationPath('server/models', 'user.js'),
this.props
);
this.fs.copyTpl(
this.templatePath('services/sequelize-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
case 'nedb':
dependencies.push('nedb');
dependencies.push('feathers-nedb');
this.fs.copyTpl(
this.templatePath('services/nedb-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
case 'postgres':
dependencies.push('pg');
dependencies.push('pg-hstore');
dependencies.push('sequelize');
dependencies.push('feathers-sequelize');
this.fs.copyTpl(
this.templatePath('models/sequelize-user.js'),
this.destinationPath('server/models', 'user.js'),
this.props
);
this.fs.copyTpl(
this.templatePath('services/sequelize-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
case 'sqlite':
dependencies.push('sqlite3');
dependencies.push('sequelize');
dependencies.push('feathers-sequelize');
this.fs.copyTpl(
this.templatePath('models/sequelize-user.js'),
this.destinationPath('server/models', 'user.js'),
this.props
);
this.fs.copyTpl(
this.templatePath('services/sequelize-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
case 'mssql':
dependencies.push('tedious');
dependencies.push('sequelize');
dependencies.push('feathers-sequelize');
this.fs.copyTpl(
this.templatePath('models/sequelize-user.js'),
this.destinationPath('server/models', 'user.js'),
this.props
);
this.fs.copyTpl(
this.templatePath('services/sequelize-user.js'),
this.destinationPath('server/services', 'user.js'),
this.props
);
break;
}

this.fs.copy(this.templatePath('static'), this.destinationPath());
this.fs.copy(this.templatePath('static/.*'), this.destinationPath());

this.fs.copyTpl(
this.templatePath('app.js'),
this.destinationPath('server', 'app.js'),
this.props
);

this.fs.copyTpl(
this.templatePath('middleware.js'),
this.destinationPath('server/middleware', 'index.js'),
this.props
);

this.fs.copyTpl(
this.templatePath('config.default.json'),
this.destinationPath('config', 'default.json'),
this.props
);

this.fs.copyTpl(
this.templatePath('config.production.json'),
this.destinationPath('config', 'production.json'),
this.props
);

this.fs.copyTpl(
this.templatePath('package.json'),
this.destinationPath('package.json'),
this.props
);

this.log(this.props);

this.npmInstall(dependencies, { save: true });

this.npmInstall([
'babel',
'jshint',
'mocha',
'feathers'
'request'
], { saveDev: true});
}
});
29 changes: 29 additions & 0 deletions app/templates/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { join } from 'path';
import feathers from 'feathers';
import configuration from 'feathers-configuration';
import hooks from 'feathers-hooks';<% if (providers.indexOf('rest') !== -1) { %>
import rest from 'feathers-rest';
import bodyParser from 'body-parser';
<% } %><% if (providers.indexOf('socket.io') !== -1) { %>import socketio from 'feathers-socketio';<% } %><% if (providers.indexOf('primus') !== -1) { %>import primus from 'feathers-primus';<% } %>
<% if (authentication.length) { %>import feathersAuth from 'feathers-authentication';<% } %>
import middleware from './middleware';
import services from './services';
import myHooks from './hooks';

let app = feathers();

app.configure(configuration(join(__dirname, '..')))
.configure(hooks())<% if(providers.indexOf('rest') !== -1) { %>
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.configure(rest())<% } %><% if (providers.indexOf('socket.io') !== -1) { %>
.configure(socketio())<% } %><% if(providers.indexOf('primus') !== -1) { %>
.configure(primus({
transformer: 'sockjs'
}))<% } %><% if (authentication.length) { %>
.configure(feathersAuth(app.get('auth').local))<% } %>
.configure(services)
.configure(myHooks)
.configure(middleware);

export default app;
3 changes: 3 additions & 0 deletions app/templates/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var feathersAuth = require('feathers-authentication').default;

export default feathersAuth();
Loading

0 comments on commit 1d7cad9

Please sign in to comment.