Run a dependency command when file changes

Hi all,

I have a Phoenix project PrjA with a path dependency DepA.

My goal is to be able to edit DepA and have the PrjA server to:

  1. recompile
  2. reload
  3. run a mix task of DepA

1 is easy, using the :reloadable_apps option of Phoenix.CodeReloader.reload
2 is not so important

Regarding 3, I would love to run mix assets.build in DepA from PrjA.
My current solution is to run a task that rebuilds the assets in another shell from DepA.
I was wondering if there’s a way to avoid that.

Cheers

If this is for development than I think the easiest way is to use GitHub - falood/exsync: Yet another elixir reloader. and set its reload_callback to a function that calls the mix task. You’ll also have to use a path dependency.

1 Like

A generic solution is to use entr. GitHub - eradman/entr: Run arbitrary commands when files change

It is a command line tool that lets you do anything when any files change.

For example, here is how I “re-create docs when any of the lib files change”:

find lib/ | entr -s 'mix format; mix docs -f html;'
2 Likes

TIL. Super cool!