Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/api.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-define(MAD,[compile/1,app/1,get/1,release/1,resolve/1,clean/1,
start/1,attach/1,stop/1,sh/1,deps/1,up/1,fetch/1,
static/1,eunit/1,strip/1]).
static/1,eunit/1,strip/1,ez/1]).

-type return() :: [] | true | false | {ok,any()} | {error,any()}.

Expand All @@ -20,3 +20,4 @@
-spec static(list(string())) -> return().
-spec eunit(list(string())) -> return().
-spec strip(list(string())) -> return().
-spec ez(list(string())) -> return().
2 changes: 1 addition & 1 deletion include/mad.hrl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-define(VERSION,"a14d11").
-define(VERSION,"ce47d7").
3 changes: 2 additions & 1 deletion src/mad.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ atomize("sh") -> 'sh';
atomize("rep"++_) -> 'sh';
atomize("pla"++_) -> 'resolve';
atomize("str"++_) -> 'strip';
atomize("ez") -> 'ez';
atomize(Else) -> Else.

profile() -> application:get_env(mad,profile,mad_local).
Expand All @@ -69,7 +70,7 @@ help() -> info("MAD Manage Dependencies ~s~n",[?VERSION]),
info("~n"),
info(" invoke = mad | mad list~n"),
info(" list = [] | command [options] list ~n"),
info(" command = app [web|mqtt] <name> | deps | clean | compile | strip~n"),
info(" command = app [web|mqtt] <name> | deps | clean | compile | strip | ez~n"),
info(" | bundle [beam|script] <name> | get <repo> | up [name] ~n"),
info(" | start | stop | attach | repl | static <min> ~n"),
return(false).
1 change: 1 addition & 0 deletions src/mad_local.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ up(Params) -> mad_git:up(Params).
fetch(Params) -> mad_git:fetch(Params).
eunit(Params) -> mad_eunit:main_test(Params).
sh(Params) -> mad_repl:sh(Params).
ez(Params) -> mad_ez:main(Params).
52 changes: 52 additions & 0 deletions src/package/mad_ez.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-module(mad_ez).
-description("EZ bundle").
-compile(export_all).
%cd path/to/app; mad ez
main(_) ->
Base = filename:basename(mad_utils:cwd()),
[AppFile] = mad_repl:wildcards(["ebin/*.app"]),
Vsn = vsn(AppFile),
{Name,App} = case lists:suffix("-" ++ Vsn,Base) of
true -> {Base,Base -- ["-"++Vsn]};
false -> {Base++"-"++Vsn,Base}
end,
Rename = fun(F)->
Path = filename:join([Name, "ebin", filename:basename(F)]),
mad:info("Ez ~s~n",[Path]),
Path
end,
Files = static() ++ beams(Rename,fun read/1),
{ok,_}= zip:create(Name ++ ".ez", Files, opts()),
{ok,App}.

opts() -> [{compress,all},{uncompress,[".beam",".app",".so"]}].
read(F)-> {ok, B} = file:read_file(filename:absname(F)), B.
vsn(F) -> case file:consult( F ) of
{ ok, [{application,_,Terms}|_]} ->
proplists:get_value(vsn, Terms, []);
_ -> []
end.
id(X) -> X.

static() ->
Name = "static.gz",
{ok,{_,Bin}} = zip:create(Name,
[ begin
mad:info("static: ~ts~n",[F]),
{ binary_to_list(base64:encode(unicode:characters_to_binary(F))), element(2,file:read_file(F)) }
end
|| F <- mad_repl:wildcards(["priv/**"]), not filelib:is_dir(F) ],
[{compress,all},memory]),
[ { Name, Bin } ].

beams() -> beams(fun id/1, fun read/1).
beams(Fun,Read) ->
[ { Fun(F), Read(F) } ||
F <- mad_repl:wildcards(["ebin/*","sys.config",".applist"]) ].

privs() -> privs(fun id/1, fun read/1).
privs(Fun,Read) ->
[ { Fun(F), Read(F) } ||
F <- mad_repl:wildcards(["priv/**"]), not filelib:is_dir(p(F)) ].

p(F) -> mad:info("~p~n",[F]),F.