File: generate_app.escript

package info (click to toggle)
elixir-lang 1.14.0.dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,204 kB
  • sloc: erlang: 9,877; sh: 311; makefile: 276
file content (13 lines) | stat: -rwxr-xr-x 579 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env escript
%% -*- erlang -*-

main([Source, Target, Version]) ->
  {ok, [{application, Name, Props0}]} = file:consult(Source),
  Ebin = filename:dirname(Target),
  Files = filelib:wildcard(filename:join(Ebin, "*.beam")),
  Mods = [list_to_atom(filename:basename(F, ".beam")) || F <- Files],
  Props1 = lists:keyreplace(modules, 1, Props0, {modules, Mods}),
  Props = lists:keyreplace(vsn, 1, Props1, {vsn, Version}),
  AppDef = io_lib:format("~tp.~n", [{application, Name, Props}]),
  ok = file:write_file(Target, AppDef),
  io:format("Generated ~ts app~n", [Name]).