Browse Source

mad static min

Namdak Tonpa 9 years ago
parent
commit
226d92cb14
5 changed files with 16 additions and 2 deletions
  1. 1 1
      include/mad.hrl
  2. BIN
      mad
  3. 1 1
      src/mad.erl
  4. 13 0
      src/mad_static.erl
  5. 1 0
      src/profile/mad_local.erl

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"f3b8b4").
+-define(VERSION,"9f2f1f").

BIN
mad


+ 1 - 1
src/mad.erl

@@ -63,5 +63,5 @@ help()            -> info("MAD Container Tool version ~s~n",[?VERSION]),
                      info("    params = [] | command [ options  ] params ~n"),
                      info("   command = app     | deps  | clean | compile | up~n"),
                      info("           | release [ beam  | ling  | script  | runc | depot ]~n"),
-                     info("           | deploy  | start | stop  | attach  | sh ~n"),
+                     info("           | deploy  | start | stop  | attach  | sh | static [ <watch|min> ] ~n"),
                      return(false).

+ 13 - 0
src/mad_static.erl

@@ -3,6 +3,19 @@
 -compile(export_all).
 -define(NODE(Bin), "node_modules/.bin/"++Bin).
 
+main(Config, ["min"]) ->
+    {ok,[SysConfig]} = file:consult("sys.config"),
+    N2O     = proplists:get_value(n2o,SysConfig,[]),
+    AppName = proplists:get_value(app,N2O,sample),
+    Minify  = proplists:get_value(minify,N2O,[]),
+    Command = lists:concat(["uglifyjs ",string:join(element(2,Minify)," "),
+                                 " -o ",element(1,Minify),"/",AppName,".js -p 5 -c -m"]),
+    io:format("Minify: ~p~n",[Command]),
+    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};

+ 1 - 0
src/profile/mad_local.erl

@@ -13,3 +13,4 @@ sh(Params)        -> mad_repl:sh(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).