Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option for custom node command to enable CoffeeScript support #15

Merged
merged 1 commit into from
Aug 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module.exports = function(grunt) {
defaults: {
src: 'test/defaults_test.js'
},
custom_cmd: {
src: 'test/custom_cmd_test.js'
},
custom_args: {
src: 'test/custom_args_test.js'
},
Expand All @@ -59,6 +62,13 @@ module.exports = function(grunt) {
port: 3000
},
defaults: {},
custom_cmd: {
options: {
script: './test/coffeescript-server.coffee',
cmd: "coffee",
output: "Express server listening on port .+"
}
},
custom_args: {
options: {
args: [ 1, 2],
Expand Down Expand Up @@ -116,6 +126,7 @@ module.exports = function(grunt) {
grunt.registerTask('test', [
'clean',
'express:defaults', 'nodeunit:defaults',
'express:custom_cmd', 'nodeunit:custom_cmd',
'express:custom_args', 'nodeunit:custom_args',
'express:custom_port', 'nodeunit:custom_port',
'express:custom_node_env', 'nodeunit:custom_node_env',
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ or within each individual server task.
```js
express: {
options: {
// Override the command used to start the server.
// (e.g. 'coffee' instead of the default 'node' to enable CoffeeScript support)
cmd: undefined,

// Will turn into: `node path/to/server.js ARG1 ARG2 ... ARGN`
args: [ ],

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"grunt-cli": "~0.1.6",
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2"
"grunt-contrib-nodeunit": "~0.1.2",
"coffee-script": "1.6.3"
},
"peerDependencies": {
"grunt": "~0.4.0"
Expand Down
1 change: 1 addition & 0 deletions tasks/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = function(grunt) {

grunt.registerMultiTask('express', 'Start an express web server', function() {
var options = this.options({
cmd: undefined,
args: [ ],
node_env: undefined,
background: true,
Expand Down
2 changes: 1 addition & 1 deletion tasks/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function(grunt) {

if (options.background) {
server = grunt.util.spawn({
cmd: process.argv[0],
cmd: options.cmd || process.argv[0],
args: options.args,
env: process.env,
fallback: options.fallback
Expand Down
8 changes: 8 additions & 0 deletions test/coffeescript-app.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict"
express = require("express")
app = module.exports = express()
app.configure ->
app.set "port", process.env.PORT or 3000

app.get "/", (req, res) ->
res.send "Howdy from CoffeeScript!"
20 changes: 20 additions & 0 deletions test/coffeescript-server.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict"

###
Test Server - CoffeeScript Edition
###
app = require("./coffeescript-app")
start = Date.now()
log = (message) ->
console.log "[" + (Date.now() - start) + "] " + message

log "Begin coffeescript-server.coffee"
setTimeout (->
module.exports = app.listen(app.get("port"), ->
log "Express server listening on port " + app.get("port")
)
), 50
setTimeout (->
log "250ms timeout"
), 250
log "End coffeescript-server.coffee"
25 changes: 25 additions & 0 deletions test/custom_cmd_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* grunt-express-server
* https://github.com/ericclemmons/grunt-express-server
*
* Copyright (c) 2013 Eric Clemmons
* Licensed under the MIT license.
*/

'use strict';

var get = require('./lib/get');

module.exports.custom_output = {
test_runs_from_coffeescript_server: function(test) {
test.expect(2);

get('http://localhost:3000/', function(res, body) {
test.equal(res.statusCode, 200, 'should return 200');
test.equal(body, 'Howdy from CoffeeScript!', 'should return message from CoffeeScript server');
test.done();
}, function(err) {
test.done();
});
}
};