Namdak Tonpa 9 years ago
parent
commit
ed24a9d441

+ 1 - 1
include/mad.hrl

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

BIN
mad


+ 1 - 1
src/compilation/mad_compile.erl

@@ -3,7 +3,7 @@
 -compile(export_all).
 
 compile(Params) ->
-    { Cwd, ConfigFile, Conf } = mad:configs(),
+    { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     mad:info("Compile Params: ~p~n",[Params]),
     Res = case Params of
          [] -> mad_compile:'compile-deps'(Cwd, ConfigFile, Conf);

+ 2 - 3
src/launching/mad_repl.erl

@@ -59,9 +59,8 @@ 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) -> put(rebar,RebarConfig), start(Params).
-
-start(Params) ->
+sh(Params) ->
+    { _Cwd,_ConfigFileName,_Config } = mad_utils:configs(),
     mad_plan:main([]),
     SystemPath = filelib:wildcard(code:root_dir() ++ "/lib/{"
               ++ string:join([atom_to_list(X)||X<-mad_repl:system()],",") ++ "}-*/ebin"),

+ 1 - 1
src/launching/mad_voxoz.erl → src/launching/mad_vz.erl

@@ -1,4 +1,4 @@
--module(mad_voxoz).
+-module(mad_vz).
 -compile(export_all).
 
 create(App,_) -> create(App).

+ 9 - 18
src/mad.erl

@@ -4,15 +4,15 @@
 -compile(export_all).
 -export([main/1]).
 
-main([]) -> help();
-main(Params) ->
-    {Other,FP} = mad_utils:fold_params(Params),
+main([])          -> help();
+main(Params)      ->
+    {Other,FP}     = mad_utils:fold_params(Params),
     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)))).
+            ({Name,Par},Errors) -> lists:flatten([errors((profile()):Name(Par))|Errors]) end, [], FP)))).
 
 help(Reason,D)    -> help(io_lib:format("~s ~p", [Reason, D])).
 help(Msg)         -> help().
@@ -28,24 +28,15 @@ help()            -> info("MAD Container Tool version ~s~n",[?VERSION]),
 
 deps(Params)      -> mad_deps:deps(Params).
 compile(Params)   -> mad_compile:compile(Params).
-app(Params)       -> mad_templates:app(Params).
+app(Params)       -> mad_static: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}.
+release(Params)   -> mad_release:release(Params).
+sh(Params)        -> mad_repl:sh(Params).
+up(Params)        -> mad_deps:up(Params).
+profile()         -> application:get_env(mad,profile,mad).
 
 unknown([])       -> skip;
 unknown(Other)    -> info("Unknown: ~p~n",[Other]), help().

+ 4 - 3
src/mad_deps.erl

@@ -3,7 +3,7 @@
 -compile(export_all).
 
 deps(Params) ->
-    { Cwd, ConfigFile, Conf } = mad:configs(),
+    { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     case mad_utils:get_value(deps, Conf, []) of
         [] -> {ok,[]};
         Deps ->
@@ -26,8 +26,9 @@ pull(Config,[F|T]) ->
                    nomatch -> mad_utils:verbose(Config,Message), true;
                    _ -> pull(Config,T) end end.
 
-up(Config,Params) ->
-    List = case Params of
+up(Params) ->
+  { _Cwd,_ConfigFileName,Config } = mad_utils:configs(),
+  List = case Params of
                 [] -> [ F || F <- mad_repl:wildcards(["deps/*"]), filelib:is_dir(F) ];
                 Apps -> [ "deps/" ++ A || A <- Apps ] end ++ ["."],
     pull(Config,List).

+ 13 - 0
src/mad_static.erl

@@ -41,3 +41,16 @@ compile_static(Files) ->
     case Res of
         {_,0,_} -> false;
         {_,_,_} -> mad:info("error while compiling assets~n"), true end.
+
+app([]) -> app(["sample"]);
+app(Params) ->
+    [Name] = Params,
+    mad_repl:load(),
+    Apps = ets:tab2list(filesystem),
+    [ case string:str(File,"priv/web") of
+       1 -> Relative = Name ++ string:substr(File, 9),
+            mad:info("Create File: ~p~n",[Relative]),
+            filelib:ensure_dir(Relative),
+            file:write_file(Relative,Bin);
+       _ -> skip
+       end || {File,Bin} <- Apps ], {ok,Name}.

+ 0 - 18
src/mad_templates.erl

@@ -1,18 +0,0 @@
--module(mad_templates).
--copyright('Maxim Sokhatsky').
--compile(export_all).
-
-app([]) -> app(["sample"]);
-app(Params) ->
-    [Name] = Params,
-    mad_repl:load(),
-    Apps = ets:tab2list(filesystem),
-    [ case string:str(File,"priv/web") of
-       1 -> Relative = Name ++ string:substr(File, 9),
-            mad:info("Create File: ~p~n",[Relative]),
-            filelib:ensure_dir(Relative),
-            file:write_file(Relative,Bin);
-       _ -> skip
-       end || {File,Bin} <-Apps], false.
-
-lib(_) -> false.

+ 7 - 0
src/mad_utils.erl

@@ -106,3 +106,10 @@ verbose(Config,Message) ->
 
 compile(_,_,_,_,_) -> false.
 
+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}.

+ 2 - 1
src/packaging/mad_ling.erl

@@ -4,8 +4,9 @@
 -compile(export_all).
 -define(ARCH, list_to_atom( case os:getenv("ARCH") of false -> "posix"; A -> A end)).
 
-main(_App) ->
+ling(Params) ->
     mad_plan:main(),
+    _App = filename:basename(case Params of [] ->   mad_utils:cwd(); E -> E end),
     mad:info("ARCH: ~p~n",         [?ARCH]),
     mad:info("Bundle Name: ~p~n",  [mad_repl:local_app()]),
     mad:info("System: ~p~n",       [mad_repl:system()]),

+ 11 - 11
src/packaging/mad_release.erl

@@ -29,15 +29,15 @@ depot_release(Name) ->
     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).
+release([])              -> release(["beam"]);
+release(["depot"])       -> release(["depot", "sample"]);
+release(["beam"])        -> release(["beam",  "sample"]);
+release(["ling"])        -> release(["ling",  "sample"]);
+release(["script"])      -> release(["script","sample"]);
+release([X])             -> release(["script", X]);
+
+release(["ling"|Name])   -> mad_ling:ling(Name);
+release(["script"|Name]) -> mad_bundle:main(filename:basename(case Name of [] -> mad_utils:cwd(); E -> E end));
+release(["depot"|Name])  -> mad_release:depot_release(Name);
+release(["beam" |Name])  -> mad_systools:beam_release(Name).
 

+ 13 - 0
src/profiles/openvz.erl

@@ -0,0 +1,13 @@
+-module(openvz).
+-compile(export_all).
+
+deps(Params)      -> mad_deps:deps(Params).
+compile(Params)   -> mad_compile:compile(Params).
+app(Params)       -> mad_static:app(Params).
+clean(Params)     -> mad_vz:clean(Params).
+start(Params)     -> mad_vz:start(Params).
+attach(Params)    -> mad_vz:attach(Params).
+stop(Params)      -> mad_vz:stop(Params).
+release(Params)   -> mad_release:release(Params).
+sh(Params)        -> {error,'N/A'}.
+up(Params)        -> mad_deps:up(Params).