 
     packageNamePrompt =>
       @exec args
+      if callback
+        callback()
+      else
+        process.exit()
 
   _add: (platforms...) ->
     platforms.unshift 'add'
     onExit = =>
-      for platform in platforms
-        fs.createReadStream("../gitignore/#{platform}.gitignore")
+      for platform in platforms when platform isnt 'add'
+        fs.createReadStream("./cake/gitignore/#{platform}.gitignore")
           .pipe(fs.createWriteStream("#{@cordovaPath}/platforms/#{platform}/.gitignore"))
-    @exec(platforms, onExit, cwd: @cordovaPath)
+    @exec(platforms, onExit, cwd: @cordovaPath, env: process.env)
 
   _remove: (platforms...) ->
     platforms.unshift 'remove'


module.exports = class Cordova extends Exec
  command: './node_modules/.bin/cordova'
  cordovaPath: './build/cordova'
  platforms: ['android', 'ios']

  init: =>
    @_initialize()
  initAndroid: =>
    @_initialize()
    @addAndroid()
  initIOS: =>
    @_initialize()
    @addIOS()
  initAll: =>
    @_initialize()
    @addAll()

  addAndroid: => @_add 'android'
  addIOS:     => @_add 'ios'

  emulateIOS:     => @_emulate 'ios'
  emulateAll:     => @_emulate @platforms...

  _initialize: (callback) ->
    wrench.rmdirSyncRecursive @cordovaPath, ->
    args = ['create', @cordovaPath]

    packageNamePrompt = (callback) =>
      commander.prompt 'Package name (optional): ', (name) =>
        name = _s.clean name
        name = "#{name.charAt(0).toLowerCase()}#{name.slice(1)}"
        if name isnt ''
          args.push name
          appNamePrompt callback
