Skip to content
This repository

Hooks #254

Merged
merged 4 commits into from almost 2 years ago

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).

added some commits May 25, 2012
[api] Add `jitsu.package.runScript`
It executes scripts from `package.json` `scripts` entry.
9df1753
[api] Implement `predeploy` hook b28c135
[dist refactor] Use `spawn-command` module 5e19559
[api] Add support for `postdeploy` hook 026cee2
Nuno Job
Collaborator
dscape commented June 20, 2012

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
dscape commented June 20, 2012

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 June 20, 2012
Maciej Małecki mmalecki closed this June 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Jun 20, 2012
[api] Add `jitsu.package.runScript`
It executes scripts from `package.json` `scripts` entry.
9df1753
[api] Implement `predeploy` hook b28c135
[dist refactor] Use `spawn-command` module 5e19559
[api] Add support for `postdeploy` hook 026cee2
This page is out of date. Refresh to see the latest.
22  lib/jitsu/commands/apps.js
@@ -77,7 +77,13 @@ apps.deploy = function (callback) {
77 77
     // these closures would need to be rearanged so that this closure can see the result of view..
78 78
     //
79 79
     apps.stop(existing.name, function (err) {
80  
-      return err ? callback(err) : apps.start(existing.name, callback);
  80
+      return err ? callback(err) : apps.start(existing.name, function (err) {
  81
+        if (err) {
  82
+          return callback(err);
  83
+        }
  84
+
  85
+        jitsu.package.runScript(pkg, 'postdeploy', callback);
  86
+      });
81 87
     });
82 88
     //}
83 89
     //else {
@@ -110,12 +116,18 @@ apps.deploy = function (callback) {
110 116
       return callback(err, true, true);
111 117
     }
112 118
 
113  
-    jitsu.package.updateTarball(null, pkg, existing, firstSnapshot, function (err, snapshot) {
  119
+    jitsu.package.runScript(pkg, 'predeploy', function (err) {
114 120
       if (err) {
115  
-        return callback(err, snapshot);
  121
+        return callback(err);
116 122
       }
117  
-      
118  
-      updateApp(existing, snapshot);
  123
+
  124
+      jitsu.package.updateTarball(null, pkg, existing, firstSnapshot, function (err, snapshot) {
  125
+        if (err) {
  126
+          return callback(err, snapshot);
  127
+        }
  128
+
  129
+        updateApp(existing, snapshot);
  130
+      });
119 131
     });
120 132
   }
121 133
   
24  lib/jitsu/package.js
@@ -8,6 +8,7 @@
8 8
 var fs = require('fs'),
9 9
     path = require('path'),
10 10
     util = require('util'),
  11
+    spawnCommand = require('spawn-command'),
11 12
     async = require('flatiron').common.async,
12 13
     analyzer = require('require-analyzer'),
13 14
     npm = require('npm'),
@@ -626,6 +627,29 @@ package.available = function (pkg, dir, callback, createPackage) {
626 627
   });
627 628
 }
628 629
 
  630
+package.runScript = function (pkg, action, callback) {
  631
+  var command = pkg.scripts[action];
  632
+
  633
+  if (!command) {
  634
+    //
  635
+    // If there's no such script, it's all fine.
  636
+    //
  637
+    return callback();
  638
+  }
  639
+
  640
+  var child = spawnCommand(command, {
  641
+    customFds: [0, 1, 2]
  642
+  });
  643
+
  644
+  child.on('exit', function (code) {
  645
+    if (code !== 0) {
  646
+      return callback(new Error('`' + command + '` exited with code ' + code));
  647
+    }
  648
+
  649
+    callback();
  650
+  });
  651
+};
  652
+
629 653
 function searchStartScript(dir) {
630 654
   var scripts = ['server.js', 'bin/server', 'app.js', 'index.js'];
631 655
   for (i in scripts) {
3  package.json
@@ -32,7 +32,8 @@
32 32
     "require-analyzer": "0.4.0-3",
33 33
     "semver": "1.0.13",
34 34
     "complete": "0.3.x",
35  
-    "wizard": "0.0.x"
  35
+    "wizard": "0.0.x",
  36
+    "spawn-command": "0.0.x"
36 37
   },
37 38
   "devDependencies": {
38 39
     "nock": "0.8.x",
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.