diff --git a/Gruntfile.js b/Gruntfile.js index 1b98101..488cacc 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -130,14 +130,19 @@ module.exports = function(grunt) { // plugin's task(s), then test the result. 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', - 'express:custom_delay', 'nodeunit:custom_delay', - 'express:custom_output', 'nodeunit:custom_output', - 'express:stoppable', 'express:stoppable:stop', 'nodeunit:stoppable' + 'express:defaults', 'nodeunit:defaults', 'express:defaults:stop', + 'express:custom_cmd', 'nodeunit:custom_cmd', 'express:custom_cmd:stop', + 'express:custom_args', 'nodeunit:custom_args', 'express:custom_args:stop', + 'express:custom_port', 'nodeunit:custom_port', 'express:custom_port:stop', + 'express:custom_node_env', 'nodeunit:custom_node_env', 'express:custom_node_env:stop', + 'express:custom_delay', 'nodeunit:custom_delay', 'express:custom_delay:stop', + 'express:custom_output', 'nodeunit:custom_output', 'express:custom_output:stop', + 'express:stoppable', 'express:stoppable:stop', 'nodeunit:stoppable', + + // Multiple servers + 'express:custom_port', 'express:defaults', + 'nodeunit:defaults', 'nodeunit:custom_port', + 'express:custom_port:stop', 'express:defaults:stop', ]); // By default, lint and run all tests. diff --git a/tasks/express.js b/tasks/express.js index f28258a..bfced4f 100644 --- a/tasks/express.js +++ b/tasks/express.js @@ -12,9 +12,15 @@ var path = require('path'); module.exports = function(grunt) { - var server = require('./lib/server')(grunt); + var servers = {}; grunt.registerMultiTask('express', 'Start an express web server', function() { + if (!servers[this.target]) { + servers[this.target] = require('./lib/server')(grunt); + } + + var server = servers[this.target]; + var action = this.args.shift() || 'start'; var options = this.options({ cmd: process.argv[0], args: [ ], @@ -38,6 +44,6 @@ module.exports = function(grunt) { return false; } - server.start(options); + server[action](options); }); };