Browse Source

remove mincerl

Namdak Tonpa 6 years ago
parent
commit
b01d6cfe92

+ 3 - 1
README.md

@@ -3,7 +3,8 @@ MAD: Manage Dependencies
 
 [![Build Status](https://travis-ci.org/synrc/mad.svg?branch=master)](https://travis-ci.org/synrc/mad)
 
-A simple rebar-compatible dependency manager and developer tool with plugins for Windows, Linux and Mac.
+A simple rebar-compatible dependency manager and developer
+tool with plugins for Windows, Linux and Mac.
 
 ![MAD](http://synrc.com/images/mad.png)
 
@@ -22,6 +23,7 @@ Features
 * Support OTP releases and directory structure
 * Fast deps resolving and cycles detecting
 * Fast compilation
+* Small codebase: 1K LOC
 * DTL/YECC/LEEX/PORT/SCRIPT/APP/ERL compilation
 * BEAM bundles (single-file escriptized app)
 * BEAM releases (faster and smaller than RELX)

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"180e54").
+-define(VERSION,"876492").

BIN
mad


+ 1 - 1
src/compile/mad_app.erl

@@ -33,7 +33,7 @@ add_modules_property(Properties) ->
         {modules, _} -> Properties;
         _ -> Properties ++ [{modules, []}] end.
 
-apps(AppName) -> {ok,Apps} = mad_resolve:orderapps(), {applications,Apps -- [AppName]}.
+apps(AppName) -> {ok,Apps} = mad_release:orderapps(), {applications,Apps -- [AppName]}.
 generate_deps(AppName,Properties) ->
     case lists:keyfind(applications, 1, Properties) of
          false -> Properties ++ [apps(AppName)];

+ 0 - 0
src/test/mad_eunit.erl → src/mad_eunit.erl


+ 0 - 0
src/sources/mad_git.erl → src/mad_git.erl


+ 0 - 0
src/hooks/mad_hooks.erl → src/mad_hooks.erl


+ 4 - 4
src/profile/mad_local.erl → src/mad_local.erl

@@ -4,17 +4,17 @@
 
 compile(Params)   -> mad_compile:compile(Params).
 app(Params)       -> mad_static:app(Params).
-get(Params)       -> mad_git:get_repo(Params).
 release(Params)   -> mad_release:release(Params).
-resolve(Params)   -> mad_resolve:main(Params).
+strip(Params)     -> mad_release:strip(Params).
+resolve(Params)   -> mad_release:resolve(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).
-sh(Params)        -> mad_repl:sh(Params).
+get(Params)       -> mad_git:get_repo(Params).
 deps(Params)      -> mad_git:deps(Params).
 up(Params)        -> mad_git:up(Params).
 fetch(Params)     -> mad_git:fetch(Params).
 static(Params)    -> mad_static:main([],Params).
 eunit(Params)     -> mad_eunit:main_test(Params).
-strip(Params)     -> mad_strip:main(Params).
+sh(Params)        -> mad_repl:sh(Params).

+ 55 - 0
src/mad_release.erl

@@ -8,3 +8,58 @@ release(["script"])      -> release(["script","sample"]);
 release([])              -> release(["script"]);
 release([X])             -> release(["script",X]).
 
+strip(_) ->
+    beam_lib:strip_files(
+    mad_repl:wildcards(["{apps,deps,lib}/*/ebin/*.beam","ebin/*.beam"])),
+    {ok,[]}.
+
+% TOP SORT
+
+rm_dups([]) -> [];
+rm_dups([H|T]) -> case lists:member(H, T) of true -> rm_dups(T); false -> [H|rm_dups(T)] end.
+sort(Pairs) -> iterate(Pairs, [], lhs(Pairs) ++ rhs(Pairs)).
+lhs(L) -> [X || {X, _, _} <- L].
+rhs(L) -> [Y || {_, Y, _} <- L].
+rm_pairs(L1, L2) -> [All || All = {X, _Y, _} <- L2, not lists:member(X, L1)].
+subtract(L1, L2) -> [X || X <- L1, not lists:member(X, L2)].
+iterate([], L, All) -> {ok,rm_dups(L ++ subtract(All, L))};
+iterate(P, L, All) -> case subtract(lhs(P), rhs(P)) of [] -> P;
+                           Lhs -> iterate(rm_pairs(Lhs, P), L ++ Lhs, All) end.
+
+appdir(A) -> filename:join(lists:reverse(tl(tl(lists:reverse(filename:split(A)))))).
+
+triples() ->
+    lists:flatten([ case
+       file:consult(F) of
+         {ok,[{application,Name,Opt}]} ->
+              Apps1 = proplists:get_value(included_applications,Opt,[]),
+              Apps2 = proplists:get_value(applications,Opt,[]),
+              Apps = lists:usort(Apps1++Apps2),
+              Vsn  = proplists:get_value(vsn,Opt,[]),
+              [ case lists:member(A,mad_repl:system()) of
+                     false -> {A,Name,{Vsn,appdir(filename:absname(F))}};
+                     true -> [{A,Name,{Vsn,appdir(filename:absname(F))}}]++ system_deps(A) end || A <- Apps ];
+         {error,_} ->
+            mad:info("AppName: ~p~n",[F]), skip
+    end || F <- mad_repl:wildcards(["{apps,deps}/*/ebin/*.app","ebin/*.app"]), not filelib:is_dir(F) ]).
+
+orderapps() ->
+    Apps = triples(),
+    case sort(lists:flatten(Apps)) of
+         {ok,Sorted} -> {ok,Sorted};
+         _Return -> {error,"Cycling apps."} end.
+
+system_deps(A) ->
+    F = code:where_is_file(lists:concat([A,".app"])),
+    case file:consult(F) of
+         {ok,[{application,Name,Opt}]} ->
+              Vsn = proplists:get_value(vsn,Opt,[]),
+              [ {_A,Name,{Vsn,appdir(F)}} || _A <- proplists:get_value(applications,Opt,[]) ];
+         {error,_} -> [] end.
+
+resolve(_) ->
+    case orderapps() of
+         {ok,Ordered}   -> file:write_file(".applist",io_lib:format("~w",[Ordered])),
+                           mad:info("Generated ~p~n",[Ordered]),
+                           {ok,Ordered};
+         {error,Reason} -> {error,Reason} end.

+ 0 - 53
src/mad_resolve.erl

@@ -1,53 +0,0 @@
--module(mad_resolve).
--author('Maxim Sokhatsky').
--compile(export_all).
-
-% dependency graph solver
-
-sort(Pairs) -> iterate(Pairs, [], lhs(Pairs) ++ rhs(Pairs)).
-lhs(L) -> [X || {X, _, _} <- L].
-rhs(L) -> [Y || {_, Y, _} <- L].
-rm_pairs(L1, L2) -> [All || All={X, _Y, _} <- L2, not lists:member(X, L1)].
-subtract(L1, L2) -> [X || X <- L1, not lists:member(X, L2)].
-iterate([], L, All) -> {ok,rm_dups(L ++ subtract(All, L))};
-iterate(P, L, All) -> case subtract(lhs(P), rhs(P)) of [] -> P; Lhs -> iterate(rm_pairs(Lhs, P), L ++ Lhs, All) end.
-rm_dups([]) -> [];
-rm_dups([H|T]) -> case lists:member(H, T) of true -> rm_dups(T); false -> [H|rm_dups(T)] end.
-
-appdir(A) -> filename:join(lists:reverse(tl(tl(lists:reverse(filename:split(A)))))).
-
-triples() ->
-    lists:flatten([ case
-       file:consult(F) of
-         {ok,[{application,Name,Opt}]} ->
-              Apps1 = proplists:get_value(included_applications,Opt,[]),
-              Apps2 = proplists:get_value(applications,Opt,[]),
-              Apps = lists:usort(Apps1++Apps2),
-              Vsn  = proplists:get_value(vsn,Opt,[]),
-              [ case lists:member(A,mad_repl:system()) of
-                     false -> {A,Name,{Vsn,appdir(filename:absname(F))}};
-                     true -> [{A,Name,{Vsn,appdir(filename:absname(F))}}]++ system_deps(A) end || A <- Apps ];
-         {error,_} ->
-            mad:info("AppName: ~p~n",[F]), skip
-    end || F <- mad_repl:wildcards(["{apps,deps}/*/ebin/*.app","ebin/*.app"]), not filelib:is_dir(F) ]).
-
-orderapps() ->
-    Apps = triples(),
-    case sort(lists:flatten(Apps)) of
-         {ok,Sorted} -> {ok,Sorted};
-         _Return -> {error,"Cycling apps."} end.
-
-system_deps(A) ->
-    F = code:where_is_file(lists:concat([A,".app"])),
-    case file:consult(F) of
-         {ok,[{application,Name,Opt}]} ->
-              Vsn = proplists:get_value(vsn,Opt,[]),
-              [ {_A,Name,{Vsn,appdir(F)}} || _A <- proplists:get_value(applications,Opt,[]) ];
-         {error,_} -> [] end.
-
-main(_) ->
-    case orderapps() of
-         {ok,Ordered}   -> file:write_file(".applist",io_lib:format("~w",[Ordered])),
-                           mad:info("Generated ~p~n",[Ordered]),
-                           {ok,Ordered};
-         {error,Reason} -> {error,Reason} end.

+ 3 - 43
src/mad_static.erl

@@ -1,7 +1,5 @@
 -module(mad_static).
--copyright('Yuri Artemev').
 -compile(export_all).
--define(NODE(Bin), "node_modules/.bin/"++Bin).
 
 main(_Config, ["min"]) ->
     SysConfig = try {ok,[S]} = file:consult("sys.config"), S catch _:_ -> [] end,
@@ -12,48 +10,10 @@ main(_Config, ["min"]) ->
                                  " -o ",element(1,Minify),"/",AppName,".min.js"]),
     case sh:run(Command) of
          {_,0,_} -> {ok,static};
-         {_,_,_} -> mad:info("minifyjs not installed. try `npm install -g uglify`~n"), {error,"Minifier."}
-    end;
-
-main(Config, ["watch"]) ->
-    case mad_utils:get_value(static, Config, []) of
-        [] -> {ok,static};
-        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
-        [] -> {ok,static};
-        SC ->
-            Files = mad_utils:get_value(files, SC, []),
-            install_deps(), compile_static(Files)
-    end.
-
-install_deps() ->
-    case filelib:is_dir("node_modules/mincer-erl") of
-        true -> {ok,static};
-        _ ->
-            case sh:oneliner("npm install mincer-erl") of
-                {_,0,_} -> {ok,static};
-                {_,_,_} -> mad:info("error while installing mincer-erl~n"), {error,"Static install."}
-            end
+         {_,_,_} -> mad:info("minifyjs not installed. try `npm install -g uglify`~n"),
+                    {error,"Minifier."}
     end.
 
-% FIXME exit
-serve_static(Port) ->
-    PortStr = integer_to_list(Port),
-    Res = sh:oneliner([?NODE("mincer-erl-serve"), "-p " ++ PortStr]),
-    case Res of
-        {_,0,_} -> {ok,static};
-        {_,_,_} -> mad:info("error while serving assets~n"), {error,"Static assests."} end.
-
-compile_static(Files) ->
-    Res = sh:oneliner([?NODE("mincer-erl-compile")] ++ Files),
-    case Res of
-        {_,0,_} -> {ok,static};
-        {_,_,_} -> mad:info("error while compiling assets~n"), {error,"Static compile."} end.
-
 app([]) -> app(["web","sample"]);
 app([Name]) -> app(["web",Name]);
 app([Skeleton,Name|_]) ->
@@ -61,7 +21,7 @@ app([Skeleton,Name|_]) ->
     mad_repl:load(),
     Apps = ets:tab2list(filesystem),
     try
-    [ begin %io:format("File: ~p~n",[{File,Name,string:replace(File, "sample", Name, all)}]),
+    [ begin
        case string:str(File,"priv/"++Skeleton) of
        1 -> Relative = unicode:characters_to_list(Name++
                        string:replace(

+ 0 - 7
src/mad_strip.erl

@@ -1,7 +0,0 @@
--module(mad_strip).
--export([main/1]).
-
-main(_) ->
-    beam_lib:strip_files(
-    mad_repl:wildcards(["{apps,deps,lib}/*/ebin/*.beam","ebin/*.beam"])),
-    {ok,[]}.

+ 2 - 2
src/package/mad_escript.erl

@@ -4,7 +4,7 @@
 
 main(N) ->
     App = filename:basename(case N of [] -> mad_utils:cwd(); E -> E end),
-    mad_resolve:main([]),
+    mad_release:resolve([]),
     DefaultEmuArgs = "+pc unicode",
     EmuArgs = case file:consult( "escript.config" ) of
        { ok, Terms } -> proplists:get_value( emu_args, Terms, DefaultEmuArgs );
@@ -38,7 +38,7 @@ privs(Fun,Read) ->
 
 system_files() -> lists:flatten([system_files(A) || A<- mad_repl:applist(), lists:member(A,mad_repl:system()) ]).
 system_files(App) ->
-    [ { F, mad_bundle:read_file(F) } ||
+    [ { F, mad_repl:load_file(F) } ||
         F <- mad_repl:wildcards([lists:concat([code:lib_dir(App),"/ebin/*.{app,beam}"])]) ].
 
 overlay() -> overlay(fun id/1,  fun read_file/1).

+ 3 - 3
src/package/mad_systools.erl

@@ -21,13 +21,13 @@ apps(List) ->
     || {App,{Version,Dir}} <- List ] || Class <- [ebin,priv] ]).
 
 release(Name) ->
-    Triples = mad_resolve:triples(),
+    Triples = mad_release:triples(),
     Apps = lists:usort(fun({Name1,_},{Name2,_})-> Name1 =< Name2 end,
                 [{A,{B,F}}||{_,A,{B,F}}<-Triples]) ++
       [{kernel,{proplists:get_value(vsn,element(2,
                 application:get_all_key(kernel)),[]),
                 filename:absname(code:lib_dir(kernel))}}],
-    Sorted = [ lists:keyfind(A,1,Apps) || A <- element(2,mad_resolve:orderapps())],
+    Sorted = [ lists:keyfind(A,1,Apps) || A <- element(2,mad_release:orderapps())],
     {L,R}     = lists:unzip(Sorted),
     {Ver,_Dir} = lists:unzip(R),
     NameVer   = [ X || X <- lists:zip(L,Ver), element(1,X) /= active,
@@ -38,7 +38,7 @@ release(Name) ->
     {{release,{Name,Version},{erts,erlang:system_info(version)},NameVer},Sorted}.
 
 beam_release(N) ->
-    mad_resolve:main([]),
+    mad_release:resolve([]),
     Directories = mad_repl:wildcards(["{deps,apps}/*/ebin","ebin"]),
     code:add_paths(Directories),
     {Release,Apps} = release(N),

+ 1 - 1
src/provision/mad_repl.erl → src/provide/mad_repl.erl

@@ -20,7 +20,7 @@ applist() ->
          {ok,Binary} -> parse_applist(Binary);
          {error,_} ->
            case mad_repl:load_file(Name) of
-              {error,_} -> mad_resolve:main([]);
+              {error,_} -> mad_release:resolve([]);
               {ok,Plan} -> parse_applist(Plan) end end.
 
 wildcards(List) -> lists:concat([filelib:wildcard(X)||X<-List]).

+ 0 - 0
src/provision/mad_run.erl → src/provide/mad_run.erl