Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added makeSlug method

  • Loading branch information...
commit ea319ccf6c06999c408eee00b061dadb848aef8a 1 parent 6f5b4b7
Craig Condon authored September 20, 2011
4  README.md
Source Rendered
@@ -29,13 +29,13 @@ app.checkout('git@github.com:spiceapps/gittyup-test.git', function(err, result)
29 29
 
30 30
 
31 31
 
32  
-gittyup.addListener('update', function()
  32
+app.addListener('update', function()
33 33
 {
34 34
 	//start application logic here	
35 35
 });
36 36
 
37 37
 
38  
-gittyup.addListener('remove', function()
  38
+app.addListener('remove', function()
39 39
 {
40 40
 	//remove application logic here
41 41
 });
15  examples/slug.js
... ...
@@ -0,0 +1,15 @@
  1
+var gittyup = require('../lib/index'),
  2
+app = gittyup.app( { name: 'test', group: 'root' });
  3
+
  4
+
  5
+app.checkout('git@github.com:spiceapps/gittyup-test.git', function(err, result)
  6
+{
  7
+    app.makeSlug(function(err, item)
  8
+	{
  9
+		console.log(item);
  10
+	});
  11
+	
  12
+})
  13
+
  14
+//console.log("GO")
  15
+	
74  lib/app.js
@@ -4,7 +4,7 @@ link = require('./link'),
4 4
 nodefs = require('node-fs'),
5 5
 exec = require('child_process').exec,
6 6
 fs = require('fs'),
7  
-EventEmitter = require('sk/core/events');
  7
+EventEmitter = require('sk/core/events').EventEmitter;
8 8
 
9 9
 
10 10
 var App = EventEmitter.extend({
@@ -76,19 +76,34 @@ var App = EventEmitter.extend({
76 76
 			callback(err, result);
77 77
 		}
78 78
 
  79
+		var  output = ops.dir || (self.appDir + '/' + Date.now()),
  80
+		appDir = output + '/app',
  81
+		slugDir = output;// + '/slugs';
79 82
 
80  
-		var  output = ops.dir || (self.appDir + '/' + Date.now());
  83
+		
  84
+		nodefs.mkdirSync(appDir, 0755, true);
  85
+		nodefs.mkdirSync(slugDir, 0755, true);
81 86
 
82 87
 		//checkout the source which could be from a number of sources
83  
-		var ret = checkout({ source: source, app: self, output: output }, function(err, result)
  88
+		var ret = checkout({ source: source, app: self, output: appDir }, function(err, result)
84 89
 		{
85 90
 			console.log('checked out: ' + source);
86 91
 		
87 92
 			if(err) return callback(err, result);
88 93
 
89 94
 
  95
+			var app = {
  96
+				rootDir: output,
  97
+				appDir: appDir,
  98
+				slugDir: slugDir,
  99
+				app: self.name,
  100
+				createdAt: Date.now(),
  101
+				lastUsed: Date.now()
  102
+			};
  103
+
  104
+
90 105
 			//add the info the checked out items so we have reference to what's up - backups, etc.
91  
-			self._gup.checkouts.insert({ path: output, app: self.name, createdAt: Date.now(), lastUsed: Date.now() }, function(err, items)
  106
+			self._gup.checkouts.insert(app, function(err, items)
92 107
 			{
93 108
 				var item = items[0];
94 109
 
@@ -119,7 +134,12 @@ var App = EventEmitter.extend({
119 134
 
120 135
 					var linked = link(item, function(err, result)
121 136
 					{
122  
-						if(err) return callback(err);
  137
+						if(err)
  138
+						{
  139
+							//rollback immediately.
  140
+							self.rollback();
  141
+							return callback(err);
  142
+						}
123 143
 
124 144
 						onCheckout(err, item);
125 145
 					});
@@ -166,7 +186,7 @@ var App = EventEmitter.extend({
166 186
 				
167 187
 			});	
168 188
 
169  
-			console.log('Removing repo %s', item.path)
  189
+			console.log('Removing repo %s', item.appDir)
170 190
 
171 191
 			exec('rm -rf ' + item.path, callback)
172 192
 		})	
@@ -247,6 +267,44 @@ var App = EventEmitter.extend({
247 267
 		});
248 268
 	},
249 269
 
  270
+	/**
  271
+	 * slug for passing from server to server
  272
+	 */
  273
+
  274
+	'makeSlug': function(callback)
  275
+	{
  276
+		var self = this;
  277
+
  278
+		this.current(function(err, item)
  279
+		{
  280
+
  281
+			//err, no item, OR slug exists? return
  282
+			if(err || !item || item.slug) return callback(err, item);
  283
+
  284
+			
  285
+			var slugPath =  item.slugDir + '/' + item._id + '.tar.gz';
  286
+
  287
+			exec('cd ' + item.appDir + '; tar -pczf '+slugPath+' ./*;', function(err, result)
  288
+			{
  289
+
  290
+				//success making the slug?
  291
+				if(!err)
  292
+				{
  293
+
  294
+					//then update the current item with the new slug
  295
+					return self._gup.checkouts.update({ _id: item._id }, { $set : { slug: slugPath }}, function(err, result)
  296
+					{
  297
+						self.current(callback);
  298
+					});
  299
+				}
  300
+
  301
+				//error
  302
+				callback(err, result);
  303
+				
  304
+			});
  305
+		});
  306
+	},
  307
+
250 308
 
251 309
 	/**
252 310
 	 */
@@ -309,7 +367,7 @@ var App = EventEmitter.extend({
309 367
 
310 368
 	'_update': function()
311 369
 	{
312  
-		self.emit('update');	
  370
+		this.emit('update');	
313 371
 	},
314 372
 
315 373
 	/**
@@ -317,7 +375,7 @@ var App = EventEmitter.extend({
317 375
 
318 376
 	'_remove': function()
319 377
 	{
320  
-		self.emit('remove');
  378
+		this.emit('remove');
321 379
 	}
322 380
 
323 381
 });
3  lib/index.js
@@ -15,8 +15,7 @@ var Gittyup = Structr({
15 15
 			apps: '/etc/gittyup/apps',
16 16
 			db: '/etc/gittyup/db'
17 17
 		};
18  
-
19  
-
  18
+		
20 19
 		this.db = gumbo.db({
21 20
 			persist: {
22 21
 				fs: this.dirs.db
6  lib/link/javascript.js
@@ -3,7 +3,7 @@ exec = require('child_process').exec;
@@ -33,7 +33,7 @@ exports.test = function(ops)
4  package.json
@@ -9,10 +9,10 @@
9 9
     },
10 10
     "main": "./lib/index.js",
11 11
     "dependencies": {
  12
+        "sk":"*",
12 13
         "structr":"*",
13 14
         "node-fs":"*",
14  
-        "gumbo":"*",
15  
-        "sk":"*"
  15
+        "gumbo":"*"
16 16
     },
17 17
     "os": [
18 18
         "linux",

0 notes on commit ea319cc

Please sign in to comment.
Something went wrong with that request. Please try again.