Packages

Embed a safe and reproductible node environment into your Elixir application

Current section

Files

Jump to
nox lib nox.grunt.ex
Raw

lib/nox.grunt.ex

defmodule Nox.Grunt do
@moduledoc """
Grunt wrapper
"""
alias Nox.Parsers.Grunt, as: Parser
@typedoc "Options used by the `run` function"
@type opts :: [opt]
@typedoc "Option values specific to the `run` function"
@type opt ::
{:force, boolean}
@doc """
Run grunt in the given dir
"""
@spec run(Nox.Env.t, Path.t, opts) :: {:ok, warnings :: [String.t] | :uptodate} | {:error, {code :: number, warnings :: [String.t], errors :: [String.t]}}
def run(env, dir, opts \\ []) do
args = if Keyword.get(opts, :force, false), do: ["--force"], else: []
stream = Nox.Cli.stream({Parser, []})
case System.cmd("grunt", args, cd: dir, into: stream, env: Nox.Nvm.sys_env(env), stderr_to_stdout: true) do
{%Parser{ warnings: warnings }, 0} -> {:ok, warnings}
{%Parser{ warnings: warnings, errors: errors }, code} ->
{:error, {code, warnings, errors}}
end
end
end