Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 97af0eb23a5ba8192c433aefd9c8ac825dab6fc5 @blai committed Feb 23, 2013
Showing with 266 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +15 −0 .jshintrc
  3. +82 −0 Gruntfile.js
  4. +22 −0 LICENSE-MIT
  5. +28 −0 README.md
  6. +24 −0 app/server.js
  7. +46 −0 package.json
  8. +12 −0 public/index.html
  9. +36 −0 test/test-regarde_test.js
1 .gitignore
@@ -0,0 +1 @@
+/node_modules/
15 .jshintrc
@@ -0,0 +1,15 @@
+{
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "sub": true,
+ "undef": true,
+ "unused": true,
+ "boss": true,
+ "eqnull": true,
+ "node": true,
+ "es5": true
+}
82 Gruntfile.js
@@ -0,0 +1,82 @@
+'use strict';
+
+var path = require('path');
+
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ express: {
+ livereload: {
+ options: {
+ port: 9000,
+ bases: path.resolve('public'),
+ keepalive: true,
+ watchChanges: true,
+ server: path.resolve('./app/server')
+ }
+ }
+ },
+ jshint: {
+ options: {
+ jshintrc: '.jshintrc'
+ },
+ gruntfile: {
+ src: 'Gruntfile.js'
+ },
+ lib: {
+ src: ['lib/**/*.js']
+ },
+ test: {
+ src: ['test/**/*.js']
+ },
+ },
+ watch: {
+ gruntfile: {
+ files: '<%= jshint.gruntfile.src %>',
+ tasks: ['jshint:gruntfile']
+ },
+ // lib: {
+ // files: '<%= jshint.lib.src %>',
+ // tasks: ['jshint:lib', 'nodeunit']
+ // },
+ // test: {
+ // files: '<%= jshint.test.src %>',
+ // tasks: ['jshint:test', 'nodeunit']
+ // },
+ },
+ jsbeautifier: {
+ files: ['Gruntfile.js'],
+ options: {
+ 'indent_size': 4,
+ 'indent_char': ' ',
+ 'indent_level': 0,
+ 'indent_with_tabs': false,
+ 'preserve_newlines': true,
+ 'max_preserve_newlines': 10,
+ 'jslint_happy': false,
+ 'brace_style': 'collapse',
+ 'keep_array_indentation': false,
+ 'keep_function_indentation': false,
+ 'space_before_conditional': true,
+ 'eval_code': false,
+ 'indent_case': false,
+ 'unescape_strings': false
+ }
+ }
+ });
+
+ // These plugins provide necessary tasks.
+ grunt.loadNpmTasks('grunt-contrib-nodeunit');
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-watch');
+ grunt.loadNpmTasks('grunt-jsbeautifier');
+ grunt.loadNpmTasks('grunt-express');
+
+ grunt.registerTask('format', ['jshint', 'jsbeautifier']);
+ grunt.registerTask('server', ['express', 'watch']);
+ // Default task.
+ grunt.registerTask('default', ['format', 'server']);
+
+};
22 LICENSE-MIT
@@ -0,0 +1,22 @@
+Copyright (c) 2013 Brian Lai
+
+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.
28 README.md
@@ -0,0 +1,28 @@
+# grunt-express-example
+
+An example for how to use socket.io and express using [grunt-express](https://github.com/blai/grunt-express)
+
+## Getting Started
+
+1. `git clone git://github.com/blai/grunt-express-example.git`
+2. `npm install`
+3. `grunt`
+
+To observe the server restart automatically when server script is changed, update `./app/server.js` line #15 - 18 changes to following, for example
+
+```javascript
+app.get('/hello', function(req, res){
+ // res.send('hello!');
+ res.send('bonjour!');
+});
+```
+
+## Documentation
+_(Coming soon)_
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2013 Brian Lai
+Licensed under the MIT license.
24 app/server.js
@@ -0,0 +1,24 @@
+'use strict';
+
+var express = require('express');
+var app = express();
+var server = require('http').createServer(app);
+var io = require('socket.io').listen(server);
+
+io.sockets.on('connection', function (socket) {
+ socket.emit('news', { hello: 'world' });
+ socket.on('my other event', function (data) {
+ console.log(data);
+ });
+});
+
+app.get('/hello', function(req, res){
+ res.send('hello!');
+ // res.send('bonjour!');
+});
+
+exports = module.exports = server;
+
+exports.use = function() {
+ app.use.apply(app, arguments);
+};
46 package.json
@@ -0,0 +1,46 @@
+{
+ "name": "grunt-express-example",
+ "description": "An example for how to use socket.io and express using grunt-express over grunt@0.4",
+ "version": "0.1.0",
+ "homepage": "https://github.com/blai/grunt-express-example",
+ "author": {
+ "name": "Brian Lai",
+ "email": "brian.lai.ym@gmail.com"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/blai/grunt-express-example.git"
+ },
+ "bugs": {
+ "url": "https://github.com/blai/grunt-express-example/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/blai/grunt-express-example/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "lib/grunt-express-example",
+ "engines": {
+ "node": ">= 0.6.0"
+ },
+ "scripts": {
+ "test": "grunt nodeunit"
+ },
+ "devDependencies": {
+ "grunt-contrib-jshint": "~0.1.1",
+ "grunt-contrib-nodeunit": "~0.1.2",
+ "grunt-contrib-watch": "~0.2.0",
+ "grunt": "~0.4.0",
+ "grunt-jsbeautifier": "~0.1.5",
+ "grunt-express": "~0.1.1"
+ },
+ "keywords": [
+ "grunt-express",
+ "example"
+ ],
+ "dependencies": {
+ "express": "~3.1.0",
+ "socket.io": "~0.9.13"
+ }
+}
12 public/index.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+ <script src="/socket.io/socket.io.js"></script>
+ <script>
+ var socket = io.connect('http://localhost:9000');
+ socket.on('news', function (data) {
+ console.log(data);
+ socket.emit('my other event', { my: 'data' });
+ });
+ </script>
+</head>
+</html>
36 test/test-regarde_test.js
@@ -0,0 +1,36 @@
+'use strict';
+
+var test_regarde = require('../lib/test-regarde.js');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports['awesome'] = {
+ setUp: function(done) {
+ // setup here
+ done();
+ },
+ 'no args': function(test) {
+ test.expect(1);
+ // tests here
+ test.equal(test_regarde.awesome(), 'awesome', 'should be awesome.');
+ test.done();
+ },
+};

0 comments on commit 97af0eb

Please sign in to comment.
Something went wrong with that request. Please try again.