"use strict";
var composer = require("./lib/composer");

module.exports = {
	deploy: function (configLocation, callback) {
		
		var gConfig = require(configLocation);
		var profileType = gConfig.type;
		delete gConfig.type;

		var loc = configLocation.split("/");
		loc.pop();
		loc.pop();
		loc = loc.join("/");

		try{
			composer.init(loc, gConfig, profileType);
		}
		catch(e){
			return callback(e);
		}

		switch (profileType) {
			case "daemon":
				composer.generateDaemon(gConfig.serviceName, function (error) {
					if (error) {
						return callback(error);
					}
					composer.buildRunDaemon(gConfig.serviceName, callback);
				});
				break;
			default:
				composer.generateService(gConfig.serviceName, function (error) {
					if (error) {
						return callback(error);
					}
					composer.buildRunService(gConfig.serviceName, callback);
				});
				break;
		}
	},
	
	getService: function(serviceName){
		return composer.getContext(serviceName, 'service');
	},
	
	stopService: function(serviceName, cb){
		var context = composer.getContext(serviceName, 'service');
		context.stop(cb);
	},
	
	getDaemon: function(daemoName){
		return composer.getContext(daemoName, 'daemon');
	},

	stopDaemon: function(daemoName, cb){
		var context = composer.getContext(daemoName, 'daemon');
		context.stop(cb);
	}
};
@@ -94,24 +94,28 @@
  (config
-Location
+OrConfigPath
 , callba
@@ -140,120 +140,197 @@
 nfig
- = require(configLocation);%0A%09%09var profileType = gConfig.type;%0A%09%09delete gConfig.type;%0A%0A%09%09var loc = configLocation
+;%0A%09%09var loc = ''; // applicable with configPath only%0A%09%09if (typeof configOrConfigPath === 'string') %7B // it's a path%0A%09%09%09gConfig = require(configOrConfigPath);%0A%09%09%09%0A%09%09%09loc = configOrConfigPath
 .spl
@@ -338,16 +338,17 @@
 t(%22/%22);%0A
+%09
 %09%09loc.po
@@ -354,16 +354,17 @@
 op();%0A%09%09
+%09
 loc.pop(
@@ -366,16 +366,17 @@
 .pop();%0A
+%09
 %09%09loc = 
@@ -394,14 +394,142 @@
 %22);%0A
+%09%09%7D else %7B // config object%0A%09%09%09gConfig = configOrConfigPath;%0A%09%09%7D%0A%09%09%0A%09%09var profileType = gConfig.type;%0A%09%09delete gConfig.type;%0A%09%09
 %0A%09%09try
+ 
 %7B%0A%09%09
@@ -582,19 +582,21 @@
 %0A%09%09catch
+ 
 (e)
+ 
 %7B%0A%09%09%09ret
@@ -616,16 +616,18 @@
 e);%0A%09%09%7D%0A
+%09%09
 %0A%09%09switc
@@ -1105,32 +1105,33 @@
 ervice: function
+ 
 (serviceName)%7B%0A%09
@@ -1123,24 +1123,25 @@
 serviceName)
+ 
 %7B%0A%09%09return c
@@ -1212,16 +1212,17 @@
 function
+ 
 (service
@@ -1222,32 +1222,33 @@
 serviceName, cb)
+ 
 %7B%0A%09%09var context 
@@ -1332,32 +1332,33 @@
 Daemon: function
+ 
 (daemoName)%7B%0A%09%09r
@@ -1352,16 +1352,17 @@
 emoName)
+ 
 %7B%0A%09%09retu
@@ -1410,16 +1410,17 @@
 ');%0A%09%7D,%0A
+%09
 %0A%09stopDa
@@ -1433,16 +1433,17 @@
 function
+ 
 (daemoNa
@@ -1449,16 +1449,17 @@
 ame, cb)
+ 
 %7B%0A%09%09var 

support composer.deploy with config object or with configPath