Permalink
Browse files

Merge remote branch 'coreyjewett/master'

Conflicts:
	lib/supervisor.js
	package.json
  • Loading branch information...
iangreenleaf committed Nov 14, 2011
2 parents 3b94376 + b3b5472 commit 171caa37cb08dcb68ef4ddd30378f3e515db9d77
Showing with 26 additions and 18 deletions.
  1. +25 −18 lib/supervisor.js
  2. +1 −0 package.json
View
@@ -1,4 +1,3 @@
-
var util = require("util");
var fs = require("fs");
var spawn = require("child_process").spawn;
@@ -7,7 +6,7 @@ var fileExtensionPattern;
exports.run = run;
function run (args) {
- var arg, next, watch, program, extensions, executor, poll_interval;
+ var arg, next, watch, program, programArgs, extensions, executor, poll_interval;
while (arg = args.shift()) {
if (arg === "--help" || arg === "-h" || arg === "-?") {
return help();
@@ -19,6 +18,11 @@ function run (args) {
extensions = args.shift();
} else if (arg === "--exec" || arg === "-x") {
executor = args.shift();
+ } else if (arg === "--") {
+ // Remaining args are: program [args, ...]
+ program = args.shift();
+ programArgs = args.slice(0);
+ break;
} else if (arg.indexOf("-") && !args.length) {
// Assume last arg is the program
program = arg;
@@ -44,22 +48,22 @@ function run (args) {
extensions += "|" + programExt;
}
fileExtensionPattern = new RegExp("^.*\.(" + extensions + ")$");
-
+
if (!executor) {
executor = (programExt === "coffee") ? "coffee" : "node";
}
-
+
util.puts("")
util.debug("Running node-supervisor with");
util.debug(" program '" + program + "'");
util.debug(" --watch '" + watch + "'");
util.debug(" --extensions '" + extensions + "'");
util.debug(" --exec '" + executor + "'");
- util.puts("")
-
+ util.puts("");
+
// if we have a program, then run it, and restart when it crashes.
// if we have a watch folder, then watch the folder for changes and restart the prog
- startProgram(program, executor);
+ startProgram(program, executor, programArgs);
var watchItems = watch.split(',');
watchItems.forEach(function (watchItem) {
if (!watchItem.match(/^\/.*/)) { // watch is not an absolute path
@@ -73,7 +77,7 @@ function run (args) {
});
};
-function print (m, n) { util.print(m+(!n?"\n":"")); return print }
+function print (m, n) { util.print(m+(!n?"\n":"")); return print; }
function help () {
print
@@ -114,16 +118,19 @@ function help () {
(" supervisor myapp.js")
(" supervisor myapp.coffee")
(" supervisor -w scripts -e myext -x myrunner myapp")
- (" supervisor -w lib -w server.js -w config.js server.js")
- ("")
-}
+ ("");
+};
-function startProgram (prog, exec) {
- util.debug("Starting child process with '" + exec + " " + prog + "'");
- var child = exports.child = spawn(exec, [prog]);
- child.stdout.addListener("data", function (chunk) { chunk && util.print(chunk) });
- child.stderr.addListener("data", function (chunk) { chunk && util.debug(chunk) });
- child.addListener("exit", function () { startProgram(prog, exec) });
+function startProgram (prog, exec, args) {
+ if (args)
+ util.debug("Starting child process with '" + exec + " " + prog + " " + args + "'");
+ else
+ util.debug("Starting child process with '" + exec + " " + prog + "'");
+ var spawnme = args ? [prog].concat(args) : [prog];
+ var child = exports.child = spawn(exec, spawnme);
+ child.stdout.addListener("data", function (chunk) { chunk && util.print(chunk); });
+ child.stderr.addListener("data", function (chunk) { chunk && util.debug(chunk); });
+ child.addListener("exit", function () { startProgram(prog, exec, args); });
}
var timer = null, mtime = null; crash_queued = false;
@@ -171,4 +178,4 @@ var findAllWatchFiles = function(path, callback) {
}
}
});
-}
+};
View
@@ -6,6 +6,7 @@
, "David Taylor <david@zensatellite.com>"
, "Antonio Touriño <atourino@gmail.com>"
, "Ian Young <ian.greenleaf@gmail.com>"
+ , "Corey Jewett <cj@syntheticplayground.com>"
]
, "main" : "lib/supervisor.js"
, "bin" :

0 comments on commit 171caa3

Please sign in to comment.