gradient icon indicating copy to clipboard operation
gradient copied to clipboard

Enable building as a standalone escript

Open erszcz opened this issue 3 years ago • 2 comments

In some cases it's more convenient to use a standalone CLI tool than add a dependency to a project. To enable this, we can make Gradient a standalone escript. Thanks @chouzar for the idea!

ex_doc is configured for building as an escript and it's relatively easy to set up. The real lifting is in providing a sensible CLI entry point accepting arguments and options, but with some care it might be able to use a lot of the Mix task entry point's code that we already have.

This should also allow for installing Gradient from Hex once we make it a package, but let's keep that for another ticket (#49):

mix escript.install hex gradient

erszcz avatar Feb 22 '22 09:02 erszcz

How would you run this as an escript?

./gradualizer my_folder

Something like this? Or do you have more options in mind?

Fl4m3Ph03n1x avatar Apr 20 '22 14:04 Fl4m3Ph03n1x

I would try to reuse as much code as possible with the current Mix task (which, in turn, mimics the gradualizer CLI). This means we mostly need a way to figure out code paths outside a Mix environment - I think the rest is mostly taken care of by @Premwoik in the Mix task.

Please note, though, that reusing this code would likely mean refactoring it not to use Mix, to accept extra code path options, and then calling from Mix with the Mix-provided project-specific code paths as options.

Code paths would likely only require one CLI option to be passed to the script: -pa, the same as Gradualizer or the Elixir and Erlang compilers use.

I think the script should accept directories as well as single files. It's handy to be able to type check just one file when bug hunting (either in the checked code or in the type checker itself).

erszcz avatar Apr 21 '22 08:04 erszcz