'use strict';

// This is a very simple interface
// Used to fire up gulp task in your local project
var runner = require('../utils/runner');
var cb = require('../utils/callback');
var lookupRootPath = require('../utils/lookup-root');

var commands = function (options) {
  var command = process.argv.slice(2)[0] || options.parent.rawArgs[2];
  var currentPath = process.cwd();
  var configFileName = 'gulpfile.js';

  lookupRootPath(currentPath, configFileName, function (err, rootCwd) {
    if (!rootCwd) {
      console.log(
        ' [-Error:]  This project may not be created by \'Ember-Rocks\'\n',
        '[-Error:]  Or you are not in the project root directory. Try: `pwd`\n',
        '[-Helper:] To create an \'Ember-Rocks\' project. Try: `em new myApp`'
      );
      return;
    }
    // based on the return value, root cwd assigned to `LiftOff` setting
    var cwd = rootCwd || currentPath;
    var opts = {
      cwd:        cwd,
      configPath: cwd + '/' + configFileName
    };

    switch (command) {
      case 'serve':
      case 's':
        runner(cb, 'serve', opts);
        break;
      case 'build':
      case 'b':
        runner(cb, 'release', opts);
        break;
      case 'test':
      case 't':
        runner(cb, 'test', opts);
        break;
      case 'mobile':
      case 'm':
        runner(cb, 'releaseMobile', opts);
        break;
      default:
        runner(cb, 'default', opts);
    }
  });
};

module.exports = commands;

@@ -94,16 +94,51 @@
 project%0A
+var Promise = require('bluebird');%0A
 var runn
@@ -166,24 +166,24 @@
 s/runner');%0A
-
 var cb = req
@@ -264,16 +264,1053 @@
 oot');%0A%0A
+function lookup (configFileName) %7B%0A  var currentPath = process.cwd();%0A%0A  return new Promise(function (resolve, reject) %7B%0A    lookupRootPath(currentPath, configFileName, function (err, rootCwd) %7B%0A      if (err) %7B%0A        reject(err);%0A      %7D%0A      if (!rootCwd) %7B%0A        var customErr = '%5B-Error:%5D  This project may not be created by %5C'Ember-Rocks%5C'%5Cn' +%0A          '%5B-Error:%5D  Or you are not in the project root directory. Try: %60pwd%60%5Cn' +%0A          '%5B-Helper:%5D To create an %5C'Ember-Rocks%5C' project. Try: %60em new myApp%60';%0A        reject(customErr);%0A      %7D%0A      resolve(rootCwd);%0A    %7D);%0A  %7D);%0A%7D%0A%0Afunction execCommand (command, opts) %7B%0A  switch (command) %7B%0A    case 'serve':%0A    case 's':%0A      runner(cb, 'serve', opts);%0A      break;%0A%0A    case 'build':%0A    case 'b':%0A      runner(cb, 'release', opts);%0A      break;%0A%0A    case 'test':%0A    case 't':%0A      runner(cb, 'test', opts);%0A      break;%0A%0A    case 'mobile':%0A    case 'm':%0A      runner(cb, 'releaseMobile', opts);%0A      break;%0A%0A    default:%0A      runner(cb, 'default', opts);%0A  %7D%0A%7D%0A%0A
 var comm
@@ -1412,43 +1412,8 @@
 2%5D;%0A
-  var currentPath = process.cwd();%0A
   va
@@ -1459,376 +1459,58 @@
 okup
-RootPath(currentPath, configFileName, function (err, rootCwd) %7B%0A    if (!rootCwd) %7B%0A      console.log(%0A        ' %5B-Error:%5D  This project may not be created by %5C'Ember-Rocks%5C'%5Cn',%0A        '%5B-Error:%5D  Or you are not in the project root directory. Try: %60pwd%60%5Cn',%0A        '%5B-Helper:%5D To create an %5C'Ember-Rocks%5C' project. Try: %60em new myApp%60'%0A      );%0A      return;
+(configFileName)%0A    .then(function (rootCwd) %7B
 %0A  
-  %7D%0A
     
@@ -1578,24 +1578,26 @@
 setting%0A    
+  
 var cwd = ro
@@ -1609,25 +1609,29 @@
  %7C%7C 
-currentPath
+process.cwd()
 ;%0A    
+  
 var 
@@ -1639,16 +1639,18 @@
 pts = %7B%0A
+  
       cw
@@ -1664,16 +1664,18 @@
    cwd,%0A
+  
       co
@@ -1719,446 +1719,108 @@
     
+  
 %7D;%0A
-%0A
     
-switch (command) %7B%0A      case 'serve':%0A      case 's':%0A        runner(cb, 'serve', opts);%0A        break;%0A      case 'build':%0A      case 'b':%0A        runner(cb, 'release', opts);%0A        break;%0A      case 'test':%0A      case 't':%0A        runner(cb, 'test', opts);%0A        break;%0A      case 'mobile':%0A      case 'm':%0A        runner(cb, 'releaseMobile', opts);%0A        break;%0A      default:%0A        runner(cb, 'default', opts
+  execCommand(command, opts);%0A    %7D)%0A    .catch(function (err) %7B%0A      console.log(err
 );%0A  
-  %7D%0A
   %7D)

promisify the commands.js