         else
           console.log "Saved to #{target}"
         if watch
-          watcher.addFileMap parsed.scripts, ({event, file}) ->
-            entry source, target, watch
+          watcher.addFileMap parsed.ordered, ({event, file, fullPath}) ->
+            entry opts
     else if not nothing
       console.log if obj then parsed else parsed.serialize()
 

class Watcher extends EventEmitter
  constructor: () ->
    @inner = {}
  addFileMap: (fileMap, cb) ->
    # the goal is to determine whether something exists...
    # we also want to anything that
    @removeOldWatchers fileMap
    for file, val of fileMap
      if not @inner[file]
        @inner[file] = fs.watch file, (evt) =>
          console.log "[#{evt}] #{file}"
          @emit 'changed', event: evt, file: file
          if cb
            cb event: evt, file: file
  removeOldWatchers: (fileMap) ->
    for file, watcher of @inner
      if not fileMap[file]
        watcher.close()
        delete @inner[file]

watcher = new Watcher()

entry = ({source, target, obj, nothing, watch}) ->
  # remove the .extension? we'll figure this one out later...
  parseFile source, (err, parsed) ->
    if err
      console.log 'ERROR'

fs = require 'fs'
path = require 'path'
_ = require 'underscore'
async = require './async'
argv = require('optimist')
  .demand(['source'])
  #.boolean('w')
  .usage('Usage: amdify [-w] -source <source_module_dir> -target <target_output_dir>')
  .argv

