Run your Elixir scripts with dependencies of your favorite Mix projects!
In Elixir scripts, you cannot use external libraries, such as Jason, by using elixir command.
If you want to use functionalities of external Mix projects, you are forced to create new Mix projects to download dependencies.
You cannot even install Mix projects globally in your system.
By using erun, new Mix projects become unnecessary for disposable scripts.
erun resolves the problem simply by wrapping Mix projects in escript.
If erun is installed with Mix dependencies you specified, you can run Elixir scripts anywhere you want.
For example, if you install erun with Jason,
%{foo: "bar"}
|> Jason.encode!
|> IO.putsthe code above (foo.exs) can be executed as
$ erun foo.exs
{"foo":"bar"}git clone git@github.com:s417-lama/erun.git defp deps do
[
{:super_package, "~> 1.0"},
...
]
endmix deps.getmix escript.install(If needed) add escript path in .bashrc.
echo 'export PATH=${HOME}/.mix/escripts:$PATH' >> ~/.bashrcor if you are using asdf,
echo 'export PATH=$(asdf where elixir)/.mix/escripts:$PATH' >> ~/.bashrcAfter that, restart a shell or run . ~/.bashrc.
$ erun -e "IO.puts :hello"
helloBy calling Erun.args/0, you can get commandline arguments.
If you save the code below
IO.inspect Erun.argsas get_args.exs, the result would be:
$ erun get_args.exs foo bar 1
["foo", "bar", "1"]Args are given as a list of string.
The implementation is so simple.
erun simply calls Code.eval_string/1 or Code.eval_file/1.