Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hooks #254

Merged
merged 4 commits into from

3 participants

Maciej Małecki Nuno Job Joshua Holbrook
Maciej Małecki

Add support for hooks.

Currently supported hooks are predeploy (executed before updating the tarball) and postdeploy (executed after application is started).

Nuno Job
Collaborator

Nice idea.

Any security concerns though?

Maciej Małecki

What kind of security concerns are you talking about? Hooks are running on user's machine, it's nothing one couldn't do anyway.

Nuno Job
Collaborator

None in particular was really just asking :)

LGTM

Maciej Małecki

OK, thanks for review Nuno. @AvianFlu @jesusabdullah wanna take a look at it or should I merge?

Joshua Holbrook

I'll take a look, but a'priori this looks awesome.

Maciej Małecki

LGTM'd by @jesusabdullah and @pksunkara on IRC, merging.

Maciej Małecki mmalecki merged commit 8695d84 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 20, 2012
  1. Maciej Małecki

    [api] Add `jitsu.package.runScript`

    mmalecki authored
    It executes scripts from `package.json` `scripts` entry.
  2. Maciej Małecki
  3. Maciej Małecki
  4. Maciej Małecki
This page is out of date. Refresh to see the latest.
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
22 lib/jitsu/commands/apps.js
View
@@ -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);
+ });
});
}
24 lib/jitsu/package.js
View
@@ -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) {
3  package.json
View
@@ -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",
Something went wrong with that request. Please try again.