From 43846d626697876ff5b7b132e79ba402c4038632 Mon Sep 17 00:00:00 2001 From: Steffen Tiedemann Christensen Date: Tue, 5 Jan 2016 23:28:12 +0100 Subject: [PATCH] Allow `command` to be a function returning an array. --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8cde79e..acb8f83 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,8 @@ Monitor.prototype.start = function() { var clock = 60000 var loop = function() { - var child = spawn(self.command[0], self.command.slice(1), { + var cmd = (typeof(self.command)=='function' ? self.command() : self.command) + var child = spawn(cmd[0], cmd.slice(1), { cwd: self.cwd, env: xtend(process.env, self.env), uid: self.uid, @@ -204,7 +205,7 @@ Monitor.prototype._stopped = function() { } var respawn = function(command, opts) { - if (!Array.isArray(command)) return respawn(command.command, command) + if (typeof(command) != 'function' && !Array.isArray(command)) return respawn(command.command, command) return new Monitor(command, opts || {}) }