Permalink
Browse files

added makeSlug method

  • Loading branch information...
1 parent 6f5b4b7 commit ea319ccf6c06999c408eee00b061dadb848aef8a @crcn crcn committed Sep 21, 2011
Showing with 89 additions and 17 deletions.
  1. +2 −2 README.md
  2. +15 −0 examples/slug.js
  3. +66 −8 lib/app.js
  4. +1 −2 lib/index.js
  5. +3 −3 lib/link/javascript.js
  6. +2 −2 package.json
View
4 README.md
@@ -29,13 +29,13 @@ app.checkout('git@github.com:spiceapps/gittyup-test.git', function(err, result)
-gittyup.addListener('update', function()
+app.addListener('update', function()
{
//start application logic here
});
-gittyup.addListener('remove', function()
+app.addListener('remove', function()
{
//remove application logic here
});
View
15 examples/slug.js
@@ -0,0 +1,15 @@
+var gittyup = require('../lib/index'),
+app = gittyup.app( { name: 'test', group: 'root' });
+
+
+app.checkout('git@github.com:spiceapps/gittyup-test.git', function(err, result)
+{
+ app.makeSlug(function(err, item)
+ {
+ console.log(item);
+ });
+
+})
+
+//console.log("GO")
+
View
74 lib/app.js
@@ -4,7 +4,7 @@ link = require('./link'),
nodefs = require('node-fs'),
exec = require('child_process').exec,
fs = require('fs'),
-EventEmitter = require('sk/core/events');
+EventEmitter = require('sk/core/events').EventEmitter;
var App = EventEmitter.extend({
@@ -76,19 +76,34 @@ var App = EventEmitter.extend({
callback(err, result);
}
+ var output = ops.dir || (self.appDir + '/' + Date.now()),
+ appDir = output + '/app',
+ slugDir = output;// + '/slugs';
- var output = ops.dir || (self.appDir + '/' + Date.now());
+
+ nodefs.mkdirSync(appDir, 0755, true);
+ nodefs.mkdirSync(slugDir, 0755, true);
//checkout the source which could be from a number of sources
- var ret = checkout({ source: source, app: self, output: output }, function(err, result)
+ var ret = checkout({ source: source, app: self, output: appDir }, function(err, result)
{
console.log('checked out: ' + source);
if(err) return callback(err, result);
+ var app = {
+ rootDir: output,
+ appDir: appDir,
+ slugDir: slugDir,
+ app: self.name,
+ createdAt: Date.now(),
+ lastUsed: Date.now()
+ };
+
+
//add the info the checked out items so we have reference to what's up - backups, etc.
- self._gup.checkouts.insert({ path: output, app: self.name, createdAt: Date.now(), lastUsed: Date.now() }, function(err, items)
+ self._gup.checkouts.insert(app, function(err, items)
{
var item = items[0];
@@ -119,7 +134,12 @@ var App = EventEmitter.extend({
var linked = link(item, function(err, result)
{
- if(err) return callback(err);
+ if(err)
+ {
+ //rollback immediately.
+ self.rollback();
+ return callback(err);
+ }
onCheckout(err, item);
});
@@ -166,7 +186,7 @@ var App = EventEmitter.extend({
});
- console.log('Removing repo %s', item.path)
+ console.log('Removing repo %s', item.appDir)
exec('rm -rf ' + item.path, callback)
})
@@ -247,6 +267,44 @@ var App = EventEmitter.extend({
});
},
+ /**
+ * slug for passing from server to server
+ */
+
+ 'makeSlug': function(callback)
+ {
+ var self = this;
+
+ this.current(function(err, item)
+ {
+
+ //err, no item, OR slug exists? return
+ if(err || !item || item.slug) return callback(err, item);
+
+
+ var slugPath = item.slugDir + '/' + item._id + '.tar.gz';
+
+ exec('cd ' + item.appDir + '; tar -pczf '+slugPath+' ./*;', function(err, result)
+ {
+
+ //success making the slug?
+ if(!err)
+ {
+
+ //then update the current item with the new slug
+ return self._gup.checkouts.update({ _id: item._id }, { $set : { slug: slugPath }}, function(err, result)
+ {
+ self.current(callback);
+ });
+ }
+
+ //error
+ callback(err, result);
+
+ });
+ });
+ },
+
/**
*/
@@ -309,15 +367,15 @@ var App = EventEmitter.extend({
'_update': function()
{
- self.emit('update');
+ this.emit('update');
},
/**
*/
'_remove': function()
{
- self.emit('remove');
+ this.emit('remove');
}
});
View
3 lib/index.js
@@ -15,8 +15,7 @@ var Gittyup = Structr({
apps: '/etc/gittyup/apps',
db: '/etc/gittyup/db'
};
-
-
+
this.db = gumbo.db({
persist: {
fs: this.dirs.db
View
6 lib/link/javascript.js
@@ -3,7 +3,7 @@ exec = require('child_process').exec;
exports.test = function(ops)
{
- var files = fs.readdirSync(ops.path);
+ var files = fs.readdirSync(ops.appDir);
for(var i = files.length; i--;)
@@ -33,7 +33,7 @@ exports.test = function(ops)
exports.link = function(ops, callback)
{
- console.log("Linking with npm: " + ops.path);
+ console.log("Linking with npm: " + ops.appDir);
- exec('sudo npm link', { cwd: ops.path }, callback);
+ exec('sudo npm link', { cwd: ops.appDir }, callback);
}
View
4 package.json
@@ -9,10 +9,10 @@
},
"main": "./lib/index.js",
"dependencies": {
+ "sk":"*",
"structr":"*",
"node-fs":"*",
- "gumbo":"*",
- "sk":"*"
+ "gumbo":"*"
},
"os": [
"linux",

0 comments on commit ea319cc

Please sign in to comment.