 Sails     = require("sails/lib/app")
 sailsLift = require("sails/bin/sails-lift")
 
+# -- PRIVATE ------------------------------------------------------------------
+
 appName      = "testApp"
 appName_path = path.join(__dirname, "../" + appName)
 
-change_path = (path) ->
+_change_path = (path) ->
   new_path = path or appName_path
   process.chdir new_path
 
 # Make existsSync not crash on older versions of Node
 fs.existsSync = fs.existsSync or path.existsSync
 
+# -- PUBLIC ------------------------------------------------------------------
+
 ###
 Create a new proyect using 'sails new' command
 @param  {[Function]} done Callback
 @return {[Function]}      Callback
 ###
-_build = (done) ->
+build = (done) ->
 
   # Cleanup old test fixtures
-  _clean()
+  clean()
   exec sailsBin + " new " + appName, (err) ->
     if done
       return done(err)  if err
       done()
 
-###*
- * @description Lift a Sails Server
- * @return      {[Functon]} Callback
 ###
-_lift = -> # dir, options, done
+@description Lift a Sails Server
+@return      {[Functon]} Callback
+###
+lift = -> # dir, options, done
   delete process.env.NODE_ENV
   args = Args([
     {dir:     Args.STRING   | Args.Optional, _default: appName_path}

      socket2.on "connect", ->
        callback null, sails, socket1, socket2

_buildAndLiftWithTwoSockets = (appName, options, callback) ->
  if typeof options is "function"
    callback = options
    options = null
  _build appName, ->
    _liftWithTwoSockets options, callback


# Exports
module.exports =
  build: _build
  clean: _clean

  # linkPlugin                 : _linkPlugin,
  lift: _lift
  buildAndLift: _buildAndLift

# liftWithTwoSockets         : _liftWithTwoSockets,
# buildAndLiftWithTwoSockets : _buildAndLiftWithTwoSockets

  dir     = args.dir
  wrench.rmdirSyncRecursive dir  if fs.existsSync(dir)

# var _linkPlugin = function(callback){
#   var origin = path.resolve(process.cwd(), '..');
#   var dist = path.resolve(process.cwd(), 'node_modules', pkg.name);
#   fs.symlink(origin, dist, callback);
# };

liftWithTwoSockets = (options, callback) ->
  if typeof options is "function"
    callback = options
    options = null
  lift options, (err, sails) ->
    return callback(err)  if err
    socket1 = _ioClient.connect("http://localhost:1342",
      "force new connection": true
