Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #254 from nodejitsu/hooks

Hooks
  • Loading branch information...
commit 8695d84d99ccefbd712bd2e8b039e659461fa41c 2 parents 5827d6f + 026cee2
@mmalecki mmalecki authored
Showing with 43 additions and 6 deletions.
  1. +17 −5 lib/jitsu/commands/apps.js
  2. +24 −0 lib/jitsu/package.js
  3. +2 −1  package.json
View
22 lib/jitsu/commands/apps.js
@@ -77,7 +77,13 @@ apps.deploy = function (callback) {
// these closures would need to be rearanged so that this closure can see the result of view..
//
apps.stop(existing.name, function (err) {
- return err ? callback(err) : apps.start(existing.name, callback);
+ return err ? callback(err) : apps.start(existing.name, function (err) {
+ if (err) {
+ return callback(err);
+ }
+
+ jitsu.package.runScript(pkg, 'postdeploy', callback);
+ });
});
//}
//else {
@@ -110,12 +116,18 @@ apps.deploy = function (callback) {
return callback(err, true, true);
}
- jitsu.package.updateTarball(null, pkg, existing, firstSnapshot, function (err, snapshot) {
+ jitsu.package.runScript(pkg, 'predeploy', function (err) {
if (err) {
- return callback(err, snapshot);
+ return callback(err);
}
-
- updateApp(existing, snapshot);
+
+ jitsu.package.updateTarball(null, pkg, existing, firstSnapshot, function (err, snapshot) {
+ if (err) {
+ return callback(err, snapshot);
+ }
+
+ updateApp(existing, snapshot);
+ });
});
}
View
24 lib/jitsu/package.js
@@ -8,6 +8,7 @@
var fs = require('fs'),
path = require('path'),
util = require('util'),
+ spawnCommand = require('spawn-command'),
async = require('flatiron').common.async,
analyzer = require('require-analyzer'),
npm = require('npm'),
@@ -626,6 +627,29 @@ package.available = function (pkg, dir, callback, createPackage) {
});
}
+package.runScript = function (pkg, action, callback) {
+ var command = pkg.scripts[action];
+
+ if (!command) {
+ //
+ // If there's no such script, it's all fine.
+ //
+ return callback();
+ }
+
+ var child = spawnCommand(command, {
+ customFds: [0, 1, 2]
+ });
+
+ child.on('exit', function (code) {
+ if (code !== 0) {
+ return callback(new Error('`' + command + '` exited with code ' + code));
+ }
+
+ callback();
+ });
+};
+
function searchStartScript(dir) {
var scripts = ['server.js', 'bin/server', 'app.js', 'index.js'];
for (i in scripts) {
View
3  package.json
@@ -32,7 +32,8 @@
"require-analyzer": "0.4.0-3",
"semver": "1.0.13",
"complete": "0.3.x",
- "wizard": "0.0.x"
+ "wizard": "0.0.x",
+ "spawn-command": "0.0.x"
},
"devDependencies": {
"nock": "0.8.x",
Please sign in to comment.
Something went wrong with that request. Please try again.