 require 'shelljs/global'
 fs = require 'fs'
-forever = require 'forever-monitor'
 
 # Runs express apps
 module.exports =
 
-  forever: forever
+  foreverPath: 'node_modules/.bin/forever'
 
   nodemonPath: 'node_modules/.bin/nodemon'
 

  start: (path, port) ->
    console.log "Starting #{path} port: #{port}"
    console.log path, @getCommand(path)
    @forever.start @getCommand(path).split(' '), @getForeverOptions(path, port)

  getForeverOptions: (path, port) ->
    sourceDir: path
    max: 1
    silent: false
    outFile: "#{path}/katon.logs"
    env:
      PORT: port

  getCommand: (path) ->
    if test '-e', "#{path}/.katon"

      start = pkg.scripts?.start
      main = pkg.main
      if main?
        start.replace 'node', @nodemonPath
      else
        start
    else 
      "#{@staticPath} #{path}"