       require('watch').watchTree dir, { persistent: true, interval: 1000 },  (file, curr, prev) =>
         @build() if curr and (curr.nlink is 0 or +curr.mtime isnt +prev?.mtime)
 
-  # TODO: move this to a separate middleware class, pass in package to call compile and content type on..
   middleware: (req, res, next) =>
     str = @compile()
     res.charset = 'utf-8'

fs           = require('fs')
path         = require('path')
uglify       = require('uglify-js')
stitch       = require('../assets/stitch')
Dependency   = require('./dependency')
Stitch       = require('./stitch')
{toArray}    = require('./utils')
mime         = require('connect').static.mime

class Package
  constructor: (name, config = {}) ->
    @name         = name
    @require      = config.require
    @libs         = toArray(config.libs || [])
    @paths        = toArray(config.paths || [])
    @modules      = toArray(config.modules || [])
    @target       = config.target
    @jsAfter      = config.jsAfter or ""
    @url          = config.url or ""
    # determine content type based on target
    @contentType  = mime.lookup(@target)
    # check required config values

  compileModules: ->
    @dependency or= new Dependency(@modules)
    @stitch       = new Stitch(@paths)
    @stuff        = @dependency.resolve().concat(@stitch.resolve())
    stitch(identifier: @require, modules: @stuff)

  compileLibs: ->
    (fs.readFileSync(lib, 'utf8') for lib in @libs).join("\n")

  compile: (minify = false) ->

          _path  = require.resolve(path.resolve(_path))
          delete require.cache[_path]
          result.push require(_path)
        # TODO: do we want a minify option for css??
        result.join("\n")
    catch ex
      console.trace ex
      # only return when in server/watch mode, otherwise exit
      switch @argv.command
        when "server" then return "console.log(\"#{ex}\");"
        when "watch"  then return ""
        else process.exit(1)

  isJavascript: ->
    @contentType is "application/javascript"
