Skip to content

Commit

Permalink
feat(sockets): add app prompt to ask for socket
Browse files Browse the repository at this point in the history
  • Loading branch information
balthazar committed Feb 6, 2015
1 parent 57697c3 commit 263543c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ var BangularGenerator = yeoman.generators.NamedBase.extend({
});

if (this.sockets) {
this.template('mongo/socket.js', 'server/api/' + this.fileName + '/' + this.fileName + 'socket.js');
this.template('mongo/socket.js', 'server/api/' + this.fileName + '/' + this.fileName + '.socket.js');

genUtils.rewriteFile({
file: 'server/config/socket.js',
file: 'server/config/sockets.js',
needle: '// sockets insert',
splicable: [
'require(\'../api/' + this.fileName + '/' + this.fileName + '.socket.js\')'
Expand Down
15 changes: 14 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,20 @@ var BangularGenerator = yeoman.generators.Base.extend({
});
}

done();
if (props.backend === 'mongo') {
self.prompt({
type: 'confirm',
name: 'sockets',
message: 'Do you want to add socket support?',
default: false
}, function (props) {
self.filters.sockets = props.sockets;
done();
});
} else {
done();
}

});
},

Expand Down
3 changes: 2 additions & 1 deletion app/templates/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"angular-cookies": "~1.3.0"<% } %><% if (filters.ngResource) { %>,
"angular-resource": "~1.3.0"<% } %><% if (filters.ngSanitize) { %>,
"angular-sanitize": "~1.3.0"<% } %><% if (filters.ngAnimate) { %>,
"angular-animate": "~1.3.0"<% } %>
"angular-animate": "~1.3.0"<% } %><% if (filters.sockets) { %>,
"angular-socket-io": "^0.7.0"<% } %>
},
"devDependencies": {
"angular-mocks": "~1.3.0",
Expand Down
3 changes: 2 additions & 1 deletion app/templates/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<div ng-view></div>

<!-- build:js app.js -->
<!-- build:js app.js --><% if (filters.sockets) { %>
<script src="socket.io/socket.io.js"></script><% } %>
<!-- bower:js -->
<!-- endinject -->

Expand Down
3 changes: 2 additions & 1 deletion app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"method-override": "^2.3.1",<% if (filters.backend === 'mongo') { %>
"mongoose": "^3.8.22",<% } %>
"morgan": "^1.5.1",<% if (filters.backend === 'restock') { %>
"request": "^2.51.1",<% } %>
"request": "^2.51.1",<% } %><% if (filters.sockets) { %>
"socket.io": "^1.3.2",<% } %>
"should": "^4.6.2",
"supertest": "^0.15.0"
},
Expand Down
4 changes: 3 additions & 1 deletion app/templates/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var mongoose = require('mongoose');
mongoose.connect(config.mongo.uri, config.mongo.options);<% } %>

var app = express();
var server = require('http').createServer(app);
var server = require('http').createServer(app);<% if (filters.sockets) { %>
var socket = require('socket.io')(server, { serveClient: true });
require('./config/sockets.js')(socket);<% } %>

require('./config/express')(app);
require('./routes')(app);
Expand Down
31 changes: 30 additions & 1 deletion test/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('Launching app generator tests', function () {
.withPrompt({
name: 'Test',
backend: 'mongo',
modules: []
modules: [],
sockets: false
})
.on('end', done);

Expand Down Expand Up @@ -110,6 +111,34 @@ describe('Launching app generator tests', function () {

});

describe('', function () {

before(function (done) {

helpers.run(path.join(__dirname, '../app'))
.inDir(path.join(os.tmpdir(), './tmp'))
.withOptions({ 'skipInstall': true })
.withPrompt({
name: 'Test',
backend: 'mongo',
modules: [],
sockets: true
})
.on('end', done);

});

it('should have socket dependency, config and requires', function () {
assert.fileContent('package.json', '"socket.io":');
assert.fileContent('bower.json', '"angular-socket-io":');
assert.fileContent('client/index.html', 'socket.io/socket.io.js');
assert.file('server/config/sockets.js');
assert.fileContent('server/server.js', 'var socket = require(\'socket.io\')');
assert.fileContent('server/server.js', 'require(\'./config/sockets.js\')(socket);');
});

});

describe('', function () {

before(function (done) {
Expand Down

0 comments on commit 263543c

Please sign in to comment.