@@ -336,9 +336,53 @@ defmodule Mix.Tasks.Deps.Compile do
336336 [ "compile-package" , "--target" , "erlang" , "--package" , package , "--out" , out , "--lib" , lib ] }
337337
338338 shell_cmd! ( dep , config , command )
339+
340+ if ! Keyword . get ( opts , :app , true ) == false do
341+ generate_gleam_app_file ( opts )
342+ end
343+
339344 Code . prepend_path ( Path . join ( out , "ebin" ) , cache: true )
340345 end
341346
347+ defp gleam_extra_applications ( config ) do
348+ config
349+ |> Map . get ( :extra_applications , [ ] )
350+ |> Enum . map ( & String . to_atom / 1 )
351+ end
352+
353+ defp gleam_mod ( config ) do
354+ case config [ :mod ] do
355+ nil -> [ ]
356+ mod -> { String . to_atom ( mod ) , [ ] }
357+ end
358+ end
359+
360+ defp generate_gleam_app_file ( opts ) do
361+ toml = File . cd! ( opts [ :dest ] , fn -> Mix.Gleam . load_config ( "." ) end )
362+
363+ module =
364+ quote do
365+ def project do
366+ [
367+ app: unquote ( toml . name ) |> String . to_atom ( ) ,
368+ version: "#{ unquote ( toml . version ) } "
369+ ]
370+ end
371+
372+ def application do
373+ [
374+ mod: unquote ( gleam_mod ( toml ) ) ,
375+ extra_applications: unquote ( gleam_extra_applications ( toml ) )
376+ ]
377+ end
378+ end
379+
380+ module_name = String . to_atom ( "Gleam.#{ toml . name } " )
381+ Module . create ( module_name , module , Macro.Env . location ( __ENV__ ) )
382+ Mix.Project . push ( module_name )
383+ Mix.Tasks.Compile.App . run ( [ ] )
384+ end
385+
342386 defp make_command ( dep ) do
343387 makefile_win? = makefile_win? ( dep )
344388
0 commit comments