Browse Source

ver cd /Users/5HT/depot/synrc

Namdak Tonpa 10 years ago
parent
commit
d0a5089187
11 changed files with 75 additions and 58 deletions
  1. BIN
      mad
  2. 1 1
      rebar.config
  3. 1 1
      src/compile/mad_app.erl
  4. 1 1
      src/compile/mad_dtl.erl
  5. 1 1
      src/compile/mad_erl.erl
  6. 16 16
      src/mad.erl
  7. 3 2
      src/mad_bundle.erl
  8. 2 2
      src/mad_create.erl
  9. 38 24
      src/mad_deps.erl
  10. 1 1
      src/mad_run.erl
  11. 11 9
      src/mad_static.erl

BIN
mad


+ 1 - 1
rebar.config

@@ -1,2 +1,2 @@
 {deps_dir,"deps"}.
-{deps, [{sh, ".*", {git, "git://github.com/synrc/sh", {tag, "0.9"}}}]}.
+{deps, [{sh, ".*", {git, "git://github.com/synrc/sh", {tag, "master"}}}]}.

+ 1 - 1
src/compile/mad_app.erl

@@ -15,7 +15,7 @@ compile(File,_Inc,Bin,_Opt,_Deps) ->
     AppFile = filename:join(Bin, app_src_to_app(File)),
     Compiled = mad_compile:is_compiled(AppFile, File),
     if  Compiled =:= false ->
-        io:format("Writing ~s~n\r", [AppFile]),
+        io:format("Writing ~s~n\r", [AppFile -- mad_utils:cwd()]),
         BeamFiles = filelib:wildcard("*.beam", Bin),
         Modules = [list_to_atom(filename:basename(X, ".beam")) || X <- BeamFiles],
         [Struct|_] = mad_utils:consult(File),

+ 1 - 1
src/compile/mad_dtl.erl

@@ -47,7 +47,7 @@ compile_erlydtl_files(Opts) ->
         BeamFile = file_to_beam(OutDir, atom_to_list(ModuleName)),
         Compiled = mad_compile:is_compiled(BeamFile, F),
         if  Compiled =:= false ->
-            io:format("DTL Compiling ~s~n\r", [F]),
+            io:format("DTL Compiling ~s~n\r", [F -- mad_utils:cwd()]),
             erlydtl:compile(F, ModuleName, Opts3);
         true -> ok end
     end,

+ 1 - 1
src/compile/mad_erl.erl

@@ -11,7 +11,7 @@ compile(File,Inc,Bin,Opt,Deps) ->
     if  Compiled =:= false ->
         Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
 %        io:format("Compiling ~s~n Opts ~p~n Deps~p~n", [File,Opts1,Deps]),
-        io:format("Compiling ~s~n", [File]),
+        io:format("Compiling ~s~n", [File -- mad_utils:cwd()]),
         ret(compile:file(File, Opts1));
     true -> false end.
 

+ 16 - 16
src/mad.erl

@@ -7,7 +7,7 @@ main([]) -> help();
 main(Params) ->
 
     {Other,FP} = mad_utils:fold_params(Params),
-    io:format("Params: ~p~n\r",[FP]),
+    %io:format("Params: ~p~n\r",[FP]),
     case Other == [] of
          true -> skip;
          false -> io:format("Unknown Command or Parameter ~p~n\r",[Other]), help() end,
@@ -28,7 +28,7 @@ bool(_) -> 1.
 deps(Cwd, ConfigFile, Conf, Params) ->
     io:format("Deps Params: ~p~n",[Params]),
     case mad_utils:get_value(deps, Conf, []) of
-        [] -> ok;
+        [] -> false;
         Deps ->
             Cache = mad_utils:get_value(deps_dir, Conf, deps_fetch),
             case Cache of
@@ -37,7 +37,7 @@ deps(Cwd, ConfigFile, Conf, Params) ->
             FetchDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
             file:make_dir(FetchDir),
             mad_deps:fetch(Cwd, Conf, ConfigFile, Deps)
-    end, false.
+    end.
 
 %% compile dependencies and the app
 compile(Cwd, ConfigFile, Conf, Params) ->
@@ -56,38 +56,38 @@ plan(_Cwd,_ConfigFileName,_Config,Params) ->
     mad_plan:main([]).
 
 repl(_Cwd,_ConfigFileName,_Config,Params) ->
-%    io:format("Repl Params: ~p~n",[Params]),
+    io:format("REPL Params: ~p~n",[Params]),
     mad_repl:main(Params,_Config).
 
 bundle(_Cwd,_ConfigFileName,_Config,Params) ->
-    io:format("Tool Params: ~p~n",[Params]),
+    io:format("Bundle Params: ~p~n",[Params]),
     Name = case Params of [] -> mad_utils:cwd(); E -> E end,
-    mad_bundle:main(filename:basename(Name)), false.
+    mad_bundle:main(filename:basename(Name)).
 
 up(_Cwd,_ConfigFileName,_Config,Params) ->
     io:format("Up Params: ~p~n",[Params]),
-    mad_deps:up(Params).
+    mad_deps:up(_Config,Params).
 
 app(_Cwd,_ConfigFileName,_Config,Params) ->
     io:format("Create App Params: ~p~n",[Params]),
-    mad_create:app(Params), false.
+    mad_create:app(Params).
 
 lib(_Cwd,_ConfigFileName,_Config,Params) ->
     io:format("Create Lib Params: ~p~n",[Params]),
-    mad_create:lib(Params), false.
+    mad_create:lib(Params).
+
+clean(_Cwd,_ConfigFileName,_Config,Params) ->
+    io:format("Clean Params: ~p~n",[Params]),
+    mad_run:clean(Params).
 
 start(_Cwd,_ConfigFileName,_Config,Params) ->
     io:format("Start Params: ~p~n",[Params]),
     mad_run:start(Params), false.
 
 attach(_Cwd,_ConfigFileName,_Config,Params) ->
-%    io:format("Attach Params: ~p~n",[Params]),
+    io:format("Attach Params: ~p~n",[Params]),
     mad_run:attach(Params), false.
 
-clean(_Cwd,_ConfigFileName,_Config,Params) ->
-    io:format("Clean Params: ~p~n",[Params]),
-    mad_run:clean(Params), false.
-
 stop(_Cwd,_ConfigFileName,_Config,Params) ->
     io:format("Stop Params: ~p~n",[Params]),
     mad_run:stop(Params), false.
@@ -98,9 +98,9 @@ release(_Cwd,_ConfigFileName,_Config,Params) ->
 
 static(_Cwd,_ConfigFileName,Config,Params) ->
     io:format("Compile Static Params: ~p~n",[Params]),
-    mad_static:main(Config, Params), false.
+    mad_static:main(Config, Params).
 
-version() -> "2.2".
+version() -> "master".
 help(Reason, Data) -> help(io_lib:format("~s ~p", [Reason, Data])).
 help(Msg) -> io:format("Error: ~s~n~n", [Msg]), help().
 help() ->

+ 3 - 2
src/mad_bundle.erl

@@ -6,13 +6,14 @@ main(App) ->
     EmuArgs = "-noshell -noinput",
     Files = static() ++ beams(),
     escript:create(App,[shebang,{comment,""},{emu_args,EmuArgs},{archive,Files,[memory]}]),
-    file:change_mode(App, 8#764).
+    file:change_mode(App, 8#764),
+    false.
 
 read_file(File) -> {ok, Bin} = file:read_file(filename:absname(File)), Bin.
 
 static() -> Name = "static.gz",
     {ok,{_,Bin}} = zip:create(Name,
-        [begin io:format("F: ~p~n",[F]), F end  || F <- mad_repl:wildcards(["{apps,deps}/*/priv/**","priv/**"]), not filelib:is_dir(F) ],
+        [ F || F <- mad_repl:wildcards(["{apps,deps}/*/priv/**","priv/**"]), not filelib:is_dir(F) ],
         [{compress,all},memory]), [ { Name, Bin } ].
 
 beams() ->

+ 2 - 2
src/mad_create.erl

@@ -13,6 +13,6 @@ app(Params) ->
             filelib:ensure_dir(Relative),
             file:write_file(Relative,Bin);
        _ -> skip
-       end || {File,Bin} <-Apps].
+       end || {File,Bin} <-Apps], false.
 
-lib(_) -> ok.
+lib(_) -> false.

+ 38 - 24
src/mad_deps.erl

@@ -2,27 +2,30 @@
 -copyright('Sina Samavati').
 -compile(export_all).
 
-pull(F) ->
+pull(Config,F) ->
     io:format("==> up: ~p~n", [F]),
     {_,Status,Message} = sh:run(io_lib:format("git -C ~p pull",[F])),
     case Status of
-         0 -> false;
+         0 -> case mad_utils:get_value(verbose, Config, 0) of
+                   0 -> skip;
+                   _ -> io:format("~s",[binary_to_list(Message)])
+              end, false;
          _ -> case binary:match(Message,[<<"Aborting">>,<<"timed out">>]) of
                    nomatch -> false;
                    _ -> io:format("~s",[binary_to_list(Message)]), true end end.
 
-up(Params) ->
+up(Config,Params) ->
     List = case Params of
                 [] -> [ F || F <- mad_repl:wildcards(["deps/*"]), filelib:is_dir(F) ];
                 Apps -> [ "deps/" ++ A || A <- Apps ] end ++ ["."],
-    lists:any(fun(X) -> X end, [ pull(F) || F <- List ]).
+    lists:any(fun(X) -> X end, [ pull(Config,F) || F <- List ]).
 
-fetch(_, _Config, _, []) -> ok;
+fetch(_, _Config, _, []) -> false;
 fetch(Cwd, Config, ConfigFile, [H|T]) when is_tuple(H) =:= false -> fetch(Cwd, Config, ConfigFile, T);
 fetch(Cwd, Config, ConfigFile, [H|T]) ->
     {Name, Repo} = name_and_repo(H),
-    case get(Name) of
-        fetched -> ok;
+    Res = case get(Name) of
+        fetched -> false;
         _ ->
             {Cmd, Uri, Co} = case Repo of
                                  V={_, _, _}          -> V;
@@ -33,10 +36,14 @@ fetch(Cwd, Config, ConfigFile, [H|T]) ->
             Cache = mad_utils:get_value(cache, Config, deps_fetch),
             fetch_dep(Cwd, Config, ConfigFile, Name, Cmd1, Uri, Co, Cache)
     end,
-    fetch(Cwd, Config, ConfigFile, T).
+    case Res of
+         true -> true;
+         false -> 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};
 git_clone(Uri,Fast,TrunkPath,Rev) ->
-    {["git clone ",Fast,Uri," ",TrunkPath," && cd ",TrunkPath," && git checkout \"",Rev,"\"" ],Rev}.
+    {["git clone ",Uri," ",TrunkPath," && cd ",TrunkPath," && git checkout \"",Rev,"\"" ],Rev}.
 
 fetch_dep(Cwd, Config, ConfigFile, Name, Cmd, Uri, Co, Cache) ->
 
@@ -46,29 +53,35 @@ fetch_dep(Cwd, Config, ConfigFile, Name, Cmd, Uri, Co, Cache) ->
 
     io:format("==> dependency: ~p tag: ~p~n\r", [Uri,Co]),
 
-    % TODO: add "git clone --depth=1" option by @rillian
-
     Fast = case mad_utils:get_value(fetch_speed,Config,[]) of
-                "fast_master" -> " --depth=1 ";
+                fast_master -> " --depth=1 ";
                     _  -> "" end,
 
     {R,Co1} = case Co of
         X when is_list(X) -> git_clone(Uri,Fast,TrunkPath,X);
         {_,Rev} -> git_clone(Uri,Fast,TrunkPath,Rev);
-        Master -> {["git clone ",Fast,Uri," ",TrunkPath],lists:concat([Master])} end,
+        Master  -> git_clone(Uri,Fast,TrunkPath,Master) end,
+
+    %io:format("Fetch: ~s~n",[R]),
 
-    os:cmd(R),
+    FetchStatus = case filelib:is_dir(TrunkPath) of
+                       true -> {skip,0,list_to_binary("Directory "++TrunkPath++" exists.")};
+                       false -> sh:run(lists:concat(R)) end,
 
-    put(Name, fetched),
+    case FetchStatus of
+         {_,0,_} -> put(Name, fetched),
 
-    %% check dependencies of the dependency
-    TrunkConfigFile = filename:join(TrunkPath, ConfigFile),
-    Conf = mad_utils:consult(TrunkConfigFile),
-    Conf1 = mad_utils:script(TrunkConfigFile, Conf, Name),
-    fetch(Cwd, Config, ConfigFile, mad_utils:get_value(deps, Conf1, [])),
-    case Cache of
-       deps_fetch -> skip;
-       CacheDir -> build_dep(Cwd, Config, ConfigFile, get_publisher(Uri), Name, Cmd, Co1, CacheDir) end.
+                    %% check dependencies of the dependency
+                    TrunkConfigFile = filename:join(TrunkPath, ConfigFile),
+                    Conf = mad_utils:consult(TrunkConfigFile),
+                    Conf1 = mad_utils:script(TrunkConfigFile, Conf, Name),
+                    fetch(Cwd, Config, ConfigFile, mad_utils:get_value(deps, Conf1, [])),
+                    case Cache of
+                         deps_fetch -> false;
+                         CacheDir -> build_dep(Cwd, Config, ConfigFile,
+                                        get_publisher(Uri), Name, Cmd, Co1, CacheDir)
+                    end;
+    {_,_,FetchError} -> io:format("Fetch Error: ~s~n",[binary_to_list(FetchError)]), true end.
 
 %% build dependency based on branch/tag/commit
 build_dep(Cwd, Conf, _ConfFile, Publisher, Name, _Cmd, _Co, Dir) ->
@@ -76,7 +89,8 @@ build_dep(Cwd, Conf, _ConfFile, Publisher, Name, _Cmd, _Co, Dir) ->
     DepsDir = filename:join([mad_utils:get_value(deps_dir, Conf, ["deps"]),Name]),
     os:cmd(["cp -r ", TrunkPath, " ", DepsDir]),
     ok = file:set_cwd(DepsDir),
-    ok = file:set_cwd(Cwd).
+    ok = file:set_cwd(Cwd),
+    false.
 
 %% internal
 name_and_repo({Name, _, Repo}) when is_list(Name) -> {Name, Repo};

+ 1 - 1
src/mad_run.erl

@@ -16,4 +16,4 @@ attach(_) ->
 
 stop(_) -> ok. % TODO: stop box
 
-clean(_) -> [ file:delete(X) || X <- filelib:wildcard("{apps,deps}/*/ebin/**") ].
+clean(_) -> [ file:delete(X) || X <- filelib:wildcard("{apps,deps}/*/ebin/**") ], false.

+ 11 - 9
src/mad_static.erl

@@ -5,14 +5,14 @@
 
 main(Config, ["watch"]) ->
     case mad_utils:get_value(static, Config, []) of
-        [] -> skip;
+        [] -> false;
         SC ->
             Port = mad_utils:get_value(assets_port, SC, 3000),
             install_deps(), serve_static(Port)
     end;
 main(Config, _Params) ->
     case mad_utils:get_value(static, Config, []) of
-        [] -> skip;
+        [] -> false;
         SC ->
             Files = mad_utils:get_value(files, SC, []),
             install_deps(), compile_static(Files)
@@ -20,22 +20,24 @@ main(Config, _Params) ->
 
 install_deps() ->
     case filelib:is_dir("node_modules/mincer-erl") of
-        true -> ok;
+        true -> false;
         _ ->
             case sh:oneliner("npm install mincer-erl") of
-                {_,0,_} -> ok;
-                {_,_,_} -> exit("error while installing mincer-erl")
+                {_,0,_} -> false;
+                {_,_,_} -> io:format("error while installing mincer-erl~n"), true
             end
     end.
 
 % FIXME exit
 serve_static(Port) ->
     PortStr = integer_to_list(Port),
-    sh:oneliner([?NODE("mincer-erl-serve"), "-p " ++ PortStr]).
+    Res = sh:oneliner([?NODE("mincer-erl-serve"), "-p " ++ PortStr]),
+    case Res of
+        {_,0,_} -> false;
+        {_,_,_} -> io:format("error while serving assets~n"), true end.
 
 compile_static(Files) ->
     Res = sh:oneliner([?NODE("mincer-erl-compile")] ++ Files),
     case Res of
-        {_,0,_} -> ok;
-        {_,_,_} -> exit("error while compiling assets")
-    end.
+        {_,0,_} -> false;
+        {_,_,_} -> io:format("error while compiling assets~n"), true end.