const git = require('simple-git');
const firebase = require('firebase')
const config = require('./config')
// const cprocess = require('child_process')
// const path = __dirname + '/iotos';
// git(path).then etc..

firebase.initializeApp(config);

var ref = firebase.database().ref().child("servers")

// cprocess.exec('npm run app');


// ref.child(config.device)
ref.on('value', function (data) {
	console.log(data.val())
})

// ref.on('value', function (data) {
// 	if (data.val().rpi1 == "pull") {
// 		deploy();
// 	} 
// })

function deploy () {
  console.log('Starting Deploying aplication :-)');
  // git(path).pull('origin', 'master')
	git()
	.then(function() {
		console.log('Starting pull ... :-)))');
	})
	.pull(function(err, update) {
		if(update && update.summary.changes) {
			console.log('processing and restarting app...');
			// cprocess.exec('npm stop app');
		}
	})
	.then(function() {
	console.log('pull done.');
	});
}
@@ -358,16 +358,17 @@
 device)%0A
+%0A
 ref.on('
@@ -398,135 +398,110 @@
  %7B%0A%09
-console.log(data.val())%0A%7D)%0A%0A// ref.on('value', function (data) %7B%0A// %09if (data.val().rpi1 == %22pull%22) %7B%0A// %09%09deploy();%0A// %09%7D %0A// 
+if (data.val()%5B0%5D == config.device) %7B%0A%09%09deploy();%0A%09%7D else %7B%0A%09%09console.log('no es el dispositivo');%0A%09%7D%0A
 %7D)%0A%0A

update project