     fs.unlinkSync(@target) if fs.existsSync(@target)
 
   build: (minify = false) ->
-    console.log "Building #{@name} to target: #{@target}"
+    console.log "Building '#{@name}' target: #{@target}"
     source = @compile(minify)
     fs.writeFileSync(@target, source) if source
 

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) ->

      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)

  middleware: (req, res, next) =>
    str = @compile()
    res.charset = 'utf-8'
