Browse Source

mad refactoring

Namdak Tonpa 9 years ago
parent
commit
b547fa203a

+ 0 - 1
Makefile

@@ -1,5 +1,4 @@
 default:
 	echo "-define(VERSION,\"`git rev-parse HEAD | head -c 6`\")." > include/mad.hrl
-	mkdir -p ebin
 	erlc -o ebin deps/ling/bc/*.erl || true
 	./mad cle dep com bun mad

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"2eb6fb").
+-define(VERSION,"407e65").

BIN
mad


+ 31 - 36
src/mad_compile.erl → src/compilation/mad_compile.erl

@@ -2,21 +2,32 @@
 -copyright('Sina Samavati').
 -compile(export_all).
 
-%% compile dependencies
-deps(_, _, _, []) -> false;
+compile(Params) ->
+    { Cwd, ConfigFile, Conf } = mad:configs(),
+    mad:info("Compile Params: ~p~n",[Params]),
+    Res = case Params of
+         [] -> mad_compile:'compile-deps'(Cwd, ConfigFile, Conf);
+         __ -> mad_compile:deps(Cwd, Conf, ConfigFile, Params)
+    end,
+    case bool(Res) of
+         true -> {error,Params};
+         false -> mad_compile:'compile-apps'(Cwd, ConfigFile, Conf) end.
+
+deps(_, _, _, []) -> {ok,deps};
 deps(Cwd, Conf, ConfigFile, [H|T]) ->
     {Name, _} = mad_deps:name_and_repo(H),
     Res = case get(Name) == compiled of
-          true -> false;
+          true -> {ok,[]};
           _    -> dep(Cwd, Conf, ConfigFile, Name) end,
-    case Res of
-         true  -> true;
+    case bool(Res) of
+         true  -> {error,Name};
          false -> deps(Cwd, Conf, ConfigFile, T) end.
 
-%% compile a dependency
+bool({ok,_}) -> false;
+bool({error,_}) -> true.
+
 dep(Cwd, _Conf, ConfigFile, Name) ->
 
-    %% check dependencies of the dependency
     DepsDir = filename:join([mad_utils:get_value(deps_dir, _Conf, ["deps"])]),
     DepPath = filename:join([Cwd, DepsDir, Name]),
     mad:info("==> ~p~n",[Name]),
@@ -25,12 +36,9 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
     Conf = mad_utils:consult(DepConfigFile),
     Conf1 = mad_script:script(DepConfigFile, Conf, Name),
     Deps = mad_utils:get_value(deps, Conf1, []),
-    DepsRes = deps(Cwd, Conf, ConfigFile, Deps),
-    %mad:info("DepsStatus: ~p~n",[DepsRes]),
+    DepsRes = bool(deps(Cwd, Conf, ConfigFile, Deps)),
 
     SrcDir = filename:join([mad_utils:src(DepPath)]),
-    %mad:info("DepPath ==> ~p~n",[DepPath]),
-
     AllFiles = files(SrcDir,".yrl") ++ 
                files(SrcDir,".xrl") ++ 
                files(SrcDir,".erl") ++ % comment this to build with erlc/1
@@ -43,7 +51,7 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
             end,
 
     case Files of
-        [] -> false;
+        [] -> {ok,Name};
         Files ->
             IncDir = mad_utils:include(DepPath),
             EbinDir = mad_utils:ebin(DepPath),
@@ -57,33 +65,29 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
             file:make_dir(EbinDir),
             code:replace_path(Name,EbinDir),
 
-            %erlc(DepPath), % comment this to build with files/2
-
             Opts = mad_utils:get_value(erl_opts, Conf1, []),
             FilesStatus = compile_files(Files,IncDir, EbinDir, Opts,Includes),
             DTLStatus = mad_dtl:compile(DepPath,Conf1),
             PortStatus = lists:any(fun(X)->X end,mad_port:compile(DepPath,Conf1)),
-            %mad:info("DTL Status: ~p~n",[DTLStatus]),
-            %mad:info("Port Status: ~p~n",[PortStatus]),
-            %mad:info("Files Status: ~p~n",[FilesStatus]),
 
             put(Name, compiled),
-            DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus
-    end.
+            case DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus of
+                 true -> {error,Name};
+                 false -> {ok,Name} end end.
 
 compile_files([],_,_,_,_) -> false;
 compile_files([File|Files],Inc,Bin,Opt,Deps) ->
     case (module(filetype(File))):compile(File,Inc,Bin,Opt,Deps) of
          true -> true;
          false -> compile_files(Files,Inc,Bin,Opt,Deps);
-         _ -> mad:info("Error: ~p~n",[{File}]) end.
+         X -> mad:info("Compilation Error: ~p~n",[{X,File}]), true end.
 
-module("erl") -> mad_erl;
-module("erl.src") -> mad_utils;
-module("yrl") -> mad_yecc;
-module("xrl") -> mad_leex;
-module("app.src") -> mad_app;
-module(_) -> mad_none.
+module("erl")      -> mad_erl;
+module("erl.src")  -> mad_utils;
+module("yrl")      -> mad_yecc;
+module("xrl")      -> mad_leex;
+module("app.src")  -> mad_app;
+module(_)          -> mad_none.
 
 filetype(Path) -> string:join(tl(string:tokens(filename:basename(Path), ".")), ".").
 files(Dir,Ext) -> filelib:fold_files(Dir, Ext, true, fun(F, Acc) -> [F|Acc] end, []).
@@ -101,13 +105,4 @@ is_compiled(BeamFile, File) -> mad_utils:last_modified(BeamFile) >= mad_utils:la
     mad_compile:deps(Cwd, Conf, ConfigFile, mad_utils:get_value(deps, Conf, [])).
 
 list(X) when is_atom(X) -> atom_to_list(X);
-list(X) -> X.
-
-erlc(DepPath) ->
-    ErlFiles = filelib:wildcard(DepPath++"/src/**/*.erl"),
-    mad:info("Files: ~s~n",[[filename:basename(Erl)++" " ||Erl<-ErlFiles]]),
-    {_,Status,X} = sh:run("erlc",["-o"++DepPath++"/ebin/","-I"++DepPath++"/include"]++
-        ErlFiles,binary,filename:absname("."),[{"ERL_LIBS","apps:deps"}]),
-    case Status == 0 of
-         true -> skip;
-         false -> mad:info("Error: ~s~n",[binary_to_list(X)]) end.
+list(X) -> X.

+ 5 - 2
src/launching/mad_repl.erl

@@ -59,7 +59,10 @@ load_apps(Params,_,_Acc) -> [ application:ensure_all_started(list_to_atom(A))||A
 
 cwd() -> case  file:get_cwd() of {ok, Cwd} -> Cwd; _ -> "." end.
 
-main(Params,RebarConfig) ->
+main(Params,RebarConfig) -> put(rebar,RebarConfig), start(Params).
+
+start(Params) ->
+    mad_plan:main([]),
     SystemPath = filelib:wildcard(code:root_dir() ++ "/lib/{"
               ++ string:join([atom_to_list(X)||X<-mad_repl:system()],",") ++ "}-*/ebin"),
     UserPath   = wildcards(["{apps,deps}/*/ebin","ebin"]),
@@ -67,7 +70,7 @@ main(Params,RebarConfig) ->
     code:add_path(filename:join([cwd(),filename:basename(escript:script_name())])),
     load(),
     Config = load_config(),
-    Driver = mad_utils:get_value(shell_driver,RebarConfig,user_drv),
+    Driver = mad_utils:get_value(shell_driver,get(rebar),user_drv),
     pre(Driver),
     case os:type() of
          {win32,nt} -> shell:start();

+ 8 - 8
src/launching/mad_run.erl

@@ -1,21 +1,21 @@
 -module(mad_run).
 -compile(export_all).
 
-start(_) ->                            % run_dir > < log_dir
+start(App) ->                            % run_dir > < log_dir
+    mad_plan:main([]),
     mad:info("Scripting: ~p~n",[escript:script_name()]),
-    {_,Status,X} = sh:run("run_erl",["-daemon",".",".","exec "++escript:script_name()++" rep"],
+    {_,Status,X} = sh:run("run_erl",["-daemon",".",".","exec "++escript:script_name()++" sh"],
       binary,".",
         [{"RUN_ERL_LOG_GENERATIONS","1000"},
          {"RUN_ERL_LOG_MAXSIZE","20000000"},
          {"ERL_LIBS","apps:deps"}]),
     case Status == 0 of
-         true -> skip;
-         false -> mad:info("Shell Error: ~s~n",[binary_to_list(X)]), exit({error,X}) end.
+         true -> {ok,App};
+         false -> mad:info("Shell Error: ~s~n",[binary_to_list(X)]), {error,X} end.
 
-attach(_) ->
-    mad:info("to_erl .~n"). % use like $(mad attach)
+attach(_) -> mad:info("to_erl .~n"). % use like $(mad attach)
 
-stop(_) -> ok. % TODO: stop box
+stop(_) -> {ok,[]}.
 
 clean(_) -> [ file:delete(X) || X <- filelib:wildcard("{apps,deps}/*/ebin/**") ++
-                                     filelib:wildcard("ebin/**")], false.
+                                     filelib:wildcard("ebin/**")], {ok,[]}.

+ 11 - 4
src/launching/vox_start.erl → src/launching/mad_voxoz.erl

@@ -1,18 +1,25 @@
--module(vox_start).
+-module(mad_voxoz).
 -compile(export_all).
 
-command(Args) -> {ok,lists:map(fun start/1,Args)}.
+create(App,_) -> create(App).
+create(App) ->
+    Name = filename:basename(App,".tgz"),
+    mad:info("Unpack Container: ~p~n",[Name]),
+    {ok,Bin} = file:read_file(App),
+    erl_tar:extract({binary,zlib:gunzip(Bin)},[{cwd,lists:concat(["apps/",Name])}]).
 
 start(App) ->
-    vox:info("App: ~p~n",[App]),
+    mad:info("App: ~p~n",[App]),
     {ok,Bin}  = file:read_file(lists:concat(["apps/",App,"/config.json"])),
     {Json   } = jsone:decode(Bin),
     {Process} = proplists:get_value(<<"process">>,Json),
     Args      = proplists:get_value(<<"args">>,Process),
     Concat    = string:join(lists:map(fun(X) -> binary_to_list(X) end,Args)," "),
     {_,R,S}   = sh:run(Concat,<<"log">>,lists:concat(["apps/",App])),
-    vox:info("Oneliner: ~p~n",[Concat]),
+    mad:info("Oneliner: ~p~n",[Concat]),
     {ret(R),S}.
 
+stop(App) -> ok.
+
 ret(0) -> ok;
 ret(_) -> error.

+ 0 - 12
src/launching/vox_create.erl

@@ -1,12 +0,0 @@
--module(vox_create).
--compile(export_all).
-
-command(Args) ->
-    lists:foldl(fun create/2,[],Args),
-    {ok,?MODULE}.
-
-create(App,Acc) ->
-    Name = filename:basename(App,".tgz"),
-    vox:info("Unpack Container: ~p~n",[Name]),
-    {ok,Bin} = file:read_file(App),
-    erl_tar:extract({binary,zlib:gunzip(Bin)},[{cwd,lists:concat(["apps/",Name])}]).

+ 0 - 5
src/launching/vox_stop.erl

@@ -1,5 +0,0 @@
--module(vox_stop).
--compile(export_all).
-
-command(Args) -> vox:info("~p Args: ~p~n",[?MODULE,Args]), {ok,?MODULE}.
-

+ 54 - 113
src/mad.erl

@@ -6,118 +6,59 @@
 
 main([]) -> help();
 main(Params) ->
-
     {Other,FP} = mad_utils:fold_params(Params),
-    case Other == [] of
-         true -> skip;
-         false -> mad:info("Unknown Command or Parameter ~p~n",[Other]), help() end,
-
-    Cwd           = mad_utils:cwd(),
-    ConfigFile    = "rebar.config",
-    ConfigFileAbs = filename:join(Cwd, ConfigFile),
-    Conf          = mad_utils:consult(ConfigFileAbs),
-    Conf1         = mad_script:script(ConfigFileAbs, Conf, ""),
-
-    return(bool(lists:foldl(fun (_,true) -> true;
-          ({Name,Par},false) -> ?MODULE:Name(Cwd, ConfigFile, Conf1, Par) end, false, FP))).
-
-bool(false) -> 0;
-bool(_) -> 1.
-
-%% fetch dependencies
-deps(Cwd, ConfigFile, Conf, Params) ->
-    mad:info("Deps Params: ~p~n",[Params]),
-    case mad_utils:get_value(deps, Conf, []) of
-        [] -> false;
-        Deps ->
-            Cache = mad_utils:get_value(deps_dir, Conf, deps_fetch),
-            case Cache of
-                deps_fetch -> skip;
-                Dir -> file:make_dir(Dir) end,
-            FetchDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
-            file:make_dir(FetchDir),
-            mad_deps:fetch(Cwd, Conf, ConfigFile, Deps)
-    end.
-
-%% compile dependencies and the app
-compile(Cwd, ConfigFile, Conf, Params) ->
-    mad:info("Compile Params: ~p~n",[Params]),
-    Res = case Params of
-         [] -> mad_compile:'compile-deps'(Cwd, ConfigFile, Conf);
-         __ -> mad_compile:deps(Cwd, Conf, ConfigFile, Params)
-    end,
-    case Res of
-         true -> true;
-         false -> mad_compile:'compile-apps'(Cwd, ConfigFile, Conf) end.
-
-%% reltool apps resolving
-plan(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Plan Params: ~p~n",[Params]),
-    mad_plan:main([]).
-
-repl(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("REPL Params: ~p~n",[Params]),
-    mad_repl:main(Params,_Config).
-
-bundle(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Bundle Params: ~p~n",[Params]),
-    Name = case Params of [] -> mad_utils:cwd(); E -> E end,
-    mad_bundle:main(filename:basename(Name)).
-
-up(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Up Params: ~p~n",[Params]),
-    mad_deps:up(_Config,Params).
-
-ling(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Ling Params: ~p~n",[Params]),
-    Name = case Params of [] -> mad_utils:cwd(); E -> E end,
-    mad_ling:main(filename:basename(Name)).
-
-app(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Create App Params: ~p~n",[Params]),
-    mad_create:app(Params).
-
-lib(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Create Lib Params: ~p~n",[Params]),
-    mad_create:lib(Params).
-
-clean(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Clean Params: ~p~n",[Params]),
-    mad_run:clean(Params).
-
-start(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Start Params: ~p~n",[Params]),
-    mad_run:start(Params), false.
-
-attach(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad_run:attach(Params), false.
-
-stop(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Stop Params: ~p~n",[Params]),
-    mad_run:stop(Params), false.
-
-release(_Cwd,_ConfigFileName,_Config,Params) ->
-    mad:info("Release Params: ~p~n",[Params]),
-    mad_release:main(Params).
-
-static(_Cwd,_ConfigFileName,Config,Params) ->
-    mad:info("Compile Static Params: ~p~n",[Params]),
-    mad_static:main(Config, Params).
-
-version() -> ?VERSION.
-help(Reason, Data) -> help(io_lib:format("~s ~p", [Reason, Data])).
-help(Msg) -> mad:info("Error: ~s~n~n", [Msg]), help().
-help() ->
-    mad:info("MAD Build Tool version 2.9 #~s~n",[version()]),
-    mad:info("BNF: ~n"),
-    mad:info("    invoke := mad params~n"),
-    mad:info("    params := [] | run params ~n"),
-    mad:info("       run := command [ options ]~n"),
-    mad:info("   command := app | lib | deps | up | compile | release | bundle~n"),
-    mad:info("              clean | start | stop | attach | repl ~n"),
-    return(0).
-
-info(Format) -> io:format(lists:concat([Format,"\r"])).
+    unknown(Other),
+    return(lists:any(fun(X) -> element(1,X) == error end,
+           lists:flatten(
+           lists:foldl(
+        fun ({Name,Par},Errors) when length(Errors) > 0 -> [{error,Errors}];
+            ({Name,Par},Errors) -> lists:flatten([errors(?MODULE:Name(Par))|Errors]) end, [], FP)))).
+
+help(Reason,D)    -> help(io_lib:format("~s ~p", [Reason, D])).
+help(Msg)         -> help().
+help()            -> info("MAD Container Tool version ~s~n",[?VERSION]),
+                     info("BNF: ~n"),
+                     info("    invoke := mad params~n"),
+                     info("    params := [] | run params ~n"),
+                     info("       run := command [ options ]~n"),
+                     info("   command := app [ sample ] | deps | clean  | compile | up |~n"),
+                     info("              release [ beam | ling | runc   | depot   | script ] |~n"),
+                     info("              deploy | start | stop | attach | sh ~n"),
+                     return(false).
+
+deps(Params)      -> mad_deps:deps(Params).
+compile(Params)   -> mad_compile:compile(Params).
+app(Params)       -> mad_templates:app(Params).
+clean(Params)     -> mad_run:clean(Params).
+start(Params)     -> mad_run:start(Params).
+attach(Params)    -> mad_run:attach(Params).
+stop(Params)      -> mad_run:stop(Params).
+release(Params)   -> mad_release:main(Params).
+ling(Params)      -> mad_ling:main(filename:basename(case Params of [] ->   mad_utils:cwd(); E -> E end)).
+static(Params)    -> { _Cwd,_ConfigFileName,_Config } = configs(),          mad_static:main(_Config, Params).
+sh(Params)        -> { _Cwd,_ConfigFileName,_Config } = configs(),          mad_repl:main(Params,_Config).
+up(Params)        -> { _Cwd,_ConfigFileName,_Config } = configs(),          mad_deps:up(_Config,Params).
+
+configs() ->
+    Cwd            = mad_utils:cwd(),
+    ConfigFile     = "rebar.config",
+    ConfigFileAbs  = filename:join(Cwd, ConfigFile),
+    Conf           = mad_utils:consult(ConfigFileAbs),
+    Conf1          = mad_script:script(ConfigFileAbs, Conf, ""),
+    {Cwd,ConfigFile,Conf1}.
+
+unknown([])       -> skip;
+unknown(Other)    -> info("Unknown: ~p~n",[Other]), help().
+
+errors(false)     -> [];
+errors(true)      -> {error,unknown};
+errors({ok,L})    -> info("OK:  ~p~n",[L]), [];
+errors({error,L}) -> info("ERR: ~p~n",[L]), {error,L};
+errors(X)         -> info("ERR: ~p~n",[X]), {error,X}.
+
+return(true)      -> 1;
+return(false)     -> 0;
+return(X)         -> X.
+
+info(Format)      -> io:format(lists:concat([Format,"\r"])).
 info(Format,Args) -> io:format(lists:concat([Format,"\r"]),Args).
-
-return(X) -> X.

+ 22 - 7
src/mad_deps.erl

@@ -2,7 +2,21 @@
 -copyright('Sina Samavati').
 -compile(export_all).
 
-pull(_,[])         -> false;
+deps(Params) ->
+    { Cwd, ConfigFile, Conf } = mad:configs(),
+    case mad_utils:get_value(deps, Conf, []) of
+        [] -> {ok,[]};
+        Deps ->
+            Cache = mad_utils:get_value(deps_dir, Conf, deps_fetch),
+            case Cache of
+                deps_fetch -> skip;
+                Dir -> file:make_dir(Dir) end,
+            FetchDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
+            file:make_dir(FetchDir),
+            mad_deps:fetch(Cwd, Conf, ConfigFile, Deps)
+    end.
+
+pull(_,[])         -> {ok,[]};
 pull(Config,[F|T]) ->
     mad:info("==> up: ~p~n", [F]),
     {_,Status,Message} = sh:run(lists:concat(["cd ",F," && git pull && cd -"])),
@@ -23,7 +37,7 @@ fetch(Cwd, Config, ConfigFile, [H|T]) when is_tuple(H) =:= false -> fetch(Cwd, C
 fetch(Cwd, Config, ConfigFile, [H|T]) ->
     {Name, Repo} = name_and_repo(H),
     Res = case get(Name) of
-        fetched -> false;
+        fetched -> {ok,Name};
         _ ->
             {Cmd, Uri, Co} = case Repo of
                                  V={_, _, _}          -> V;
@@ -35,8 +49,8 @@ fetch(Cwd, Config, ConfigFile, [H|T]) ->
             fetch_dep(Cwd, Config, ConfigFile, Name, Cmd1, Uri, Co, Cache)
     end,
     case Res of
-         true -> true;
-         false -> fetch(Cwd, Config, ConfigFile, T) end.
+         {error,E} -> {error,E};
+         {ok,_} -> fetch(Cwd, Config, ConfigFile, T) end.
 
 git_clone(Uri,Fast,TrunkPath,Rev) when Rev == "head" orelse Rev == "HEAD" orelse Rev == "master" ->
     {["git clone ",Fast,Uri," ",TrunkPath],Rev};
@@ -75,11 +89,12 @@ fetch_dep(Cwd, Config, ConfigFile, Name, Cmd, Uri, Co, Cache) ->
                     Conf1 = mad_utils:script(TrunkConfigFile, Conf, Name),
                     fetch(Cwd, Config, ConfigFile, mad_utils:get_value(deps, Conf1, [])),
                     case Cache of
-                         deps_fetch -> false;
+                         deps_fetch -> {ok,Name};
                          CacheDir -> build_dep(Cwd, Config, ConfigFile,
                                         get_publisher(Uri), Name, Cmd, Co1, CacheDir)
                     end;
-    {_,_,FetchError} -> mad:info("Fetch Error: ~s~n",[binary_to_list(FetchError)]), true end.
+    {_,_,FetchError} -> mad:info("Fetch Error: ~s~n",[binary_to_list(FetchError)]),
+                        {error,binary_to_list(FetchError)} end.
 
 %% build dependency based on branch/tag/commit
 build_dep(Cwd, Conf, _ConfFile, Publisher, Name, _Cmd, _Co, Dir) ->
@@ -88,7 +103,7 @@ build_dep(Cwd, Conf, _ConfFile, Publisher, Name, _Cmd, _Co, Dir) ->
     os:cmd(["cp -r ", TrunkPath, " ", DepsDir]),
     ok = file:set_cwd(DepsDir),
     ok = file:set_cwd(Cwd),
-    false.
+    {ok,Name}.
 
 %% internal
 name_and_repo({Name, _, Repo}) when is_list(Name) -> {Name, Repo};

+ 2 - 4
src/mad_plan.erl

@@ -31,7 +31,6 @@ triples() ->
 
 orderapps() ->
     Apps = triples(),
-%    mad:info("Triples: ~p~n",[Apps]),
     case sort(lists:flatten(Apps)) of
          {ok,Sorted} -> {ok,Sorted};
          Return -> {error,{cycling_apps,Return}} end.
@@ -46,6 +45,5 @@ system_deps(A) ->
 
 main(_) ->
     case orderapps() of
-         {ok,Ordered}   -> mad:info("Ordered: ~p~n",[Ordered]),
-                           file:write_file(".applist",io_lib:format("~w",[Ordered])), false;
-         {error,Reason} -> mad:info("Ordering Error: ~p~n",[Reason]), true end.
+         {ok,Ordered}   -> file:write_file(".applist",io_lib:format("~w",[Ordered])), {ok,Ordered};
+         {error,Reason} -> {error,Reason} end.

+ 1 - 1
src/mad_create.erl → src/mad_templates.erl

@@ -1,4 +1,4 @@
--module(mad_create).
+-module(mad_templates).
 -copyright('Maxim Sokhatsky').
 -compile(export_all).
 

+ 19 - 20
src/mad_utils.erl

@@ -2,6 +2,23 @@
 -copyright('Sina Samavati').
 -compile(export_all).
 
+atomize("app"++_) -> app;
+atomize("dep")    -> deps;
+atomize("deps")   -> deps;
+atomize("cle"++_) -> clean;
+atomize("com"++_) -> compile;
+atomize("up")     -> up;
+atomize("rel"++_) -> release;
+atomize("bun"++_) -> release;
+atomize("deploy") -> deploy;
+atomize("sta"++_) -> start;
+atomize("sto"++_) -> stop;
+atomize("att"++_) -> attach;
+atomize("sh")     -> sh;
+atomize("static") -> static;
+atomize("pla"++_) -> plan;
+atomize(Else)     -> Else.
+
 cwd() -> {ok, Cwd} = file:get_cwd(), Cwd.
 
 home() -> {ok, [[H|_]]} = init:get_argument(home), H.
@@ -42,7 +59,7 @@ sub_dirs(Cwd, ConfigFile, [Dir|T], Acc) ->
     SubDir = filename:join(Cwd, Dir),
     ConfigFile1 = filename:join(SubDir, ConfigFile),
     Conf = consult(ConfigFile1),
-    Conf1 = script(ConfigFile1, Conf, Dir),
+    Conf1 = mad_script:script(ConfigFile1, Conf, Dir),
     Acc1 = sub_dirs(SubDir, ConfigFile, get_value(sub_dirs, Conf1, []),
                     Acc ++ [SubDir]),
     sub_dirs(Cwd, ConfigFile, T, Acc1).
@@ -70,29 +87,11 @@ to_atom(X) when is_list(X) -> list_to_atom(X);
 to_atom(X) when is_binary(X) -> to_atom(binary_to_list(X));
 to_atom(X) -> X.
 
-atomize("static") -> static;
-atomize("com"++_) -> compile;
-atomize("rep"++_) -> repl;
-atomize("up")     -> up;
-atomize("bun"++_) -> bundle;
-atomize("dep")    -> deps;
-atomize("deps")   -> deps;
-atomize("pla"++_) -> plan;
-atomize("app"++_) -> app;
-atomize("lib"++_) -> lib;
-atomize("sta"++_) -> start;
-atomize("att"++_) -> attach;
-atomize("sto"++_) -> stop;
-atomize("cle"++_) -> clean;
-atomize("lin"++_) -> ling;
-atomize("rel"++_) -> release;
-atomize(Else) -> Else.
-
 atomize_params_commands(Params) -> atomize_params_commands(Params,[]).
 atomize_params_commands([],New) -> New;
 atomize_params_commands([H|T], New) -> atomize_params_commands(T,[atomize(H)|New]).
 
-fold_params(Params) -> 
+fold_params(Params) ->
    Atomized = atomize_params_commands(Params),
    lists:foldl(fun(X,{Current,Result}) -> 
       case atomize(X) of

+ 2 - 1
src/packaging/mad_bundle.erl

@@ -3,11 +3,12 @@
 -compile(export_all).
 
 main(App) ->
+    mad_plan:main([]),
     EmuArgs = "-noshell -noinput +pc unicode",
     Files = static() ++ beams(fun filename:basename/1, fun read_file/1) ++ overlay(),
     escript:create(App,[shebang,{comment,""},{emu_args,EmuArgs},{archive,Files,[memory]}]),
     file:change_mode(App, 8#764),
-    false.
+    {ok,App}.
 
 id(X) -> X.
 read_file(File) -> {ok, Bin} = file:read_file(filename:absname(File)), Bin.

+ 2 - 1
src/packaging/mad_ling.erl

@@ -5,6 +5,7 @@
 -define(ARCH, list_to_atom( case os:getenv("ARCH") of false -> "posix"; A -> A end)).
 
 main(_App) ->
+    mad_plan:main(),
     mad:info("ARCH: ~p~n",         [?ARCH]),
     mad:info("Bundle Name: ~p~n",  [mad_repl:local_app()]),
     mad:info("System: ~p~n",       [mad_repl:system()]),
@@ -13,7 +14,7 @@ main(_App) ->
 %    mad:info("Files: ~p~n",        [[{filename:basename(N),size(B)}||{N,B} <- bundle()]]),
     mad:info("Overlay: ~p~n",      [[filename:basename(N)||{N,_B} <- mad_bundle:overlay()]]),
     add_apps(),
-    false.
+    {ok,_App}.
 
 cache_dir()       -> ".madaline/".
 local_map(Bucks)  -> list_to_binary(lists:map(fun({B,M,_}) -> io_lib:format("~s /~s\n",[M,B]) end,Bucks)).

+ 9 - 5
src/packaging/mad_release.erl

@@ -15,6 +15,7 @@ atomlist(TARGETS) ->
     string:join(lists:map(fun(X) -> atom_to_list(X) end,TARGETS),",").
 
 depot_release(Name) ->
+    mad_plan:main(),
     TARGETS   = [beam,ling],
     HOSTS     = [mac,bsd,windows],
     Depot     = "/Users/5HT/depot/synrc/synrc.com/apps/",
@@ -25,15 +26,18 @@ depot_release(Name) ->
                     lists:foldl(fun(B,Acc)->[contains(P,B,Acc)||P<-HOSTS] end,
                         [], wildcards(Depot,X,"/{bin,priv}/**/*")) ]
     || {_,[X],_} <- lists:flatten(Apps) ]),
-    io:format("Apps: ~p~n",[Files]).
+    io:format("DEPOT Apps: ~p~n",[Files]),
+    {ok,Name}.
 
 main([])              -> main(["beam"]);
 main(["depot"])       -> main(["depot", "sample"]);
 main(["beam"])        -> main(["beam",  "sample"]);
 main(["ling"])        -> main(["ling",  "sample"]);
 main(["script"])      -> main(["script","sample"]);
+main([X])             -> main(["script", X]);
+
+main(["ling"|Name])   -> mad_ling:main(Name);
+main(["script"|Name]) -> mad_bundle:main(filename:basename(case Name of [] -> mad_utils:cwd(); E -> E end));
+main(["depot"|Name])  -> mad_release:depot_release(Name);
+main(["beam" |Name])  -> mad_systools:beam_release(Name).
 
-main(["ling"|Name])   -> mad_ling:main(Name),              false;
-main(["script"|Name]) -> mad_bundle:main(Name),            false;
-main(["depot"|Name])  -> mad_release:depot_release(Name),  false;
-main(["beam" |Name])  -> mad_systools:beam_release(Name),  false.

+ 3 - 2
src/packaging/mad_systools.erl

@@ -35,6 +35,7 @@ release(Name) ->
     {{release,{Name,"1"},{erts,erlang:system_info(version)},NameVer},Sorted}.
 
 beam_release(Params) ->
+    mad_plan:main([]),
     [N|_] = Params,
     Directories = mad_repl:wildcards(["{deps,apps}/*/ebin","ebin"]),
     code:add_paths(Directories),
@@ -47,5 +48,5 @@ beam_release(Params) ->
             "/bin/{epmd,erlexec,run_erl,to_erl,escript,beam.smp}"]) ] ++
         apps(Apps) ++ scripts(N),
     erl_tar:create(N ++ ".tgz",Files,[compressed]),
-    mad:info("~s.boot: ~p~n",[N,Res]).
-
+    mad:info("~s.boot: ~p~n",[N,Res]),
+    {ok,N}.