-compilers  = require './compilers'
-crypto     = require 'crypto'
-fs         = require 'fs'
-resolve    = require './resolve'
-{parse}    = require './ast'
+compilers = require './compilers'
+crypto    = require 'crypto'
+fs        = require 'fs'
+{resolve} = require './resolve'
+{parse}   = require './ast'
 
-utils      = require './utils'
-prettyDate = utils.prettyDate
-readFiles  = utils.readFiles
-uniq       = utils.uniq
-fatal      = utils.fatal
+{dirname, extname, join} = require 'path'
+{fatal, prettyDate, readFiles, uniq} = require './utils'
 
-path       = require 'path'
-dirname    = path.dirname
-extname    = path.extname
-join       = path.join
+cache = {}
 
-find = (entry, callback) ->
+findDependencies = (entry, callback) ->
   count = 0
-  cache = {}
 
   alias = do ->
     base = dirname(entry).length


# Bundles up client-side JS, traversing from an initial entry point.
bundle = (entry, opts, callback) ->
  find entry, (err, requires) ->
    callback err, (wrap require, opts for _, require of requires).join('\n\n')

exports.cli = -> require './cli'

exports.createBundler = ({entry, prepend}) ->
  entry = path.resolve entry
  console.log entry
  bundler =
    bundle: (opts, callback) ->
      if typeof opts is 'function'

# Wraps a required module in a define statement.
wrap = (file) ->
  if Object.keys(file.resolved).length and file.ast
    # Update require calls
    map = {}
    for require, filename of file.resolved
