diff options
author | isaacs <i@izs.me> | 2010-05-11 03:28:08 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-05-11 03:28:08 +0400 |
commit | 786455d6516a5cbec1a2d8c21fde0f8e52aac49a (patch) | |
tree | 5e35c79465dc0969aded3bcadba2c5e3e635f462 /lib | |
parent | b689759c460108e41d9affef9f87c689055541e0 (diff) |
Add start, restart, stop, and test commands that just run scripts in the "scripts" hash.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/restart.js | 13 | ||||
-rw-r--r-- | lib/start.js | 2 | ||||
-rw-r--r-- | lib/stop.js | 2 | ||||
-rw-r--r-- | lib/test.js | 2 | ||||
-rw-r--r-- | lib/utils/lifecycle.js | 26 |
5 files changed, 42 insertions, 3 deletions
diff --git a/lib/restart.js b/lib/restart.js new file mode 100644 index 000000000..6e01b00bd --- /dev/null +++ b/lib/restart.js @@ -0,0 +1,13 @@ + +module.exports = restart + +var lifecycle = require("./utils/lifecycle") + , stop = lifecycle.cmd("stop") + , start = lifecycle.cmd("start") + +function restart (args, cb) { + stop(args, function (er) { + if (er) return log.er(cb, "Failed to stop")(er) + start(args, cb) + }) +} diff --git a/lib/start.js b/lib/start.js new file mode 100644 index 000000000..a0c0a6e1b --- /dev/null +++ b/lib/start.js @@ -0,0 +1,2 @@ + +module.exports = require("./utils/lifecycle").cmd("start") diff --git a/lib/stop.js b/lib/stop.js new file mode 100644 index 000000000..dc8c3fa22 --- /dev/null +++ b/lib/stop.js @@ -0,0 +1,2 @@ + +module.exports = require("./utils/lifecycle").cmd("stop") diff --git a/lib/test.js b/lib/test.js new file mode 100644 index 000000000..c24472a5a --- /dev/null +++ b/lib/test.js @@ -0,0 +1,2 @@ + +module.exports = require("./utils/lifecycle").cmd("test") diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 6e567fa2d..69f45c9ec 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -1,10 +1,12 @@ -module.exports = lifecycle +exports = module.exports = lifecycle +exports.cmd = cmd -var log = require("../utils/log") - , exec = require("../utils/exec") +var log = require("./log") + , exec = require("./exec") , npm = require("../../npm") , path = require("path") + , readJson = require("./read-json") function lifecycle (pkg, stage, cb) { while (pkg && pkg._data) pkg = pkg._data @@ -58,3 +60,21 @@ function makeEnv (data, prefix, env) { } return env } + +function cmd (stage) { return function (args, cb) { + var pkg = args[0] + , ver = pkg.indexOf("/") !== -1 ? "" : (args[1] || "active") + , json = path.join(npm.dir, pkg, ver, "package/package.json") + readJson(json, function (er, data) { + if (er) return log.er(cb, "Couldn't find "+path.join(pkg, ver))(er) + if ( !data.scripts + || !(stage in data.scripts) + && !("pre"+stage in data.scripts)) { + return log("Nothing to do", stage, cb) + } + lifecycle(data, "pre"+stage, function (er) { + if (er) return log.er(cb, "Failed pre"+stage)(er) + lifecycle(data, stage, cb) + }) + }) +}} |