-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from artemeff/mad-static
add static files compiler
- Loading branch information
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-module(mad_static). | ||
-copyright('Yuri Artemev'). | ||
-compile(export_all). | ||
-define(NODE(Bin), "node_modules/.bin/"++Bin). | ||
|
||
main(Config, ["watch"]) -> | ||
case mad_utils:get_value(static, Config, []) of | ||
[] -> skip; | ||
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; | ||
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; | ||
_ -> | ||
case sh:oneliner("npm install mincer-erl") of | ||
{_,0,_} -> ok; | ||
{_,_,_} -> exit("error while installing mincer-erl") | ||
end | ||
end. | ||
|
||
% FIXME exit | ||
serve_static(Port) -> | ||
PortStr = integer_to_list(Port), | ||
sh:oneliner([?NODE("mincer-erl-serve"), "-p " ++ PortStr]). | ||
|
||
compile_static(Files) -> | ||
Res = sh:oneliner([?NODE("mincer-erl-compile")] ++ Files), | ||
case Res of | ||
{_,0,_} -> ok; | ||
{_,_,_} -> exit("error while compiling assets") | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters