     get_files(File.join(["deps", atom_to_binary(dep), "ebin"]))
   end
 
-  defp elixir_files do
-    {:file, e} = :code.is_loaded(:elixir)
+  defp app_files(module) do
+    {:file, e} = :code.is_loaded(module)
     get_files(File.dirname(e))
   end
 

    Mix.Task.run :compile, args
    project = Mix.project
    if project[:app] == :elixir do
      {:ok, {'mem', zip}} = :zip.create 'mem', elixir_files, [:memory]
      script = iolist_to_binary(["#! /usr/bin/env escript\n%%! -noshell\n", zip])
      :file.write_file('elixir', script)
      set_perms('elixir')

    files = [gen_main(filename, project[:escript_main_module])|files]
    embed_elixir = project[:escript_embed_elixir] || false
    if embed_elixir do
      extra_apps = project[:escript_embed_extra_apps] || []
      files = files++Enum.reduce extra_apps, app_files(:elixir), fn app, acc ->
        Code.ensure_loaded(app)
        acc++app_files(app)
      end
    end
    files = files++Enum.reduce(project[:deps] || [], [], function do
      {dep, _, _}, acc -> acc++dep_files(dep)
