~fancycade/rebar3_tailwind

0155632e16abd0d35ec0d21570034c9cda75972b — Harley Swick 9 months ago 68acb56
Proper compile plugin
1 files changed, 31 insertions(+), 12 deletions(-)

M src/rebar3_tailwind_prv.erl
M src/rebar3_tailwind_prv.erl => src/rebar3_tailwind_prv.erl +31 -12
@@ 2,8 2,9 @@

-export([init/1, do/1, format_error/1]).

-define(PROVIDER, rebar3_tailwind).
-define(DEPS, [app_discovery]).
-define(PROVIDER, compile).
-define(NAMESPACE, tailwind).
-define(DEPS, [default, app_discovery]).

%% ===================================================================
%% Public API


@@ 12,19 13,42 @@
init(State) ->
    Provider = providers:create([
            {name, ?PROVIDER},            % The 'user friendly' name of the task
	    {namespace, ?NAMESPACE},
            {module, ?MODULE},            % The module implementation of the task
            {bare, true},                 % The task can be run by the user, always true
            {bare, false},                 % The task can be run by the user, always true
            {deps, ?DEPS},                % The list of dependencies
            {example, "rebar3 rebar3_tailwind"}, % How to use the plugin
            {example, "rebar3 tailwind compile"}, % How to use the plugin
            {opts, []},                   % list of options understood by the plugin
            {short_desc, "A rebar plugin"},
            {desc, "A rebar plugin"}
            {short_desc, "Compile tailwind css"},
            {desc, "Compile tailwind css"}
    ]),
    {ok, rebar_state:add_provider(State, Provider)}.


-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
    Apps = case rebar_state:current_app(State) of
	       undefined ->
		   rebar_state:project_apps(State);
	       AppInfo ->
		   [AppInfo]
	   end,

    [begin
	 Opts = rebar_app_info:opts(AppInfo),
	 CompileFun = fun(_Source, _Opts) ->
			      tailwind_compile()
		      end,

	 rebar_base_compiler:run(Opts, [], ["default"], CompileFun)
      end || AppInfo <- Apps],
    {ok, State}.

-spec format_error(any()) ->  iolist().
format_error(Reason) ->
    io_lib:format("~p", [Reason]).

tailwind_compile() ->
    InputSrc = 
	case application:get_env(rebar3_tailwind, input) of
	    {ok, I} -> I;


@@ 36,9 60,4 @@ do(State) ->
	    _ -> "priv/output.css"
	end,
    Cmd = io_lib:format("npx tailwindcss -i ~s -o ~s", [InputSrc, OutputDst]),
    os:cmd(Cmd),
    {ok, State}.

-spec format_error(any()) ->  iolist().
format_error(Reason) ->
    io_lib:format("~p", [Reason]).
    os:cmd(Cmd).