Run command after each compile

How does one run a command automatically after compile/recompile completes? We generate graphql client based on absinthe output.

Are watchers the only way to accomplish this or is there a post compile hook?

Maybe something like this?

defmodule MySchema do
  @after_compile __MODULE__

  def __after_compile__(_env, _bytecode) do
    with {ret, 0} <- System.cmd("echo", ["graphql schema ready!"]) do
1 Like

Add task to compilers in your mix project

Something like

defmodule MyProject.MixProject do
  use Mix.Project
  def project do
      compilers: Mix.compilers ++ [:graphql_client]

This will call mix compile.graphql_client task


Does compilers guarantee any order amongst the compilers?

Yes, it is ordered in a list

In order for this to be efficient, I should add a check which compares hash of current inputs and prior inputs and only builds if inputs have changed. I can implement this, but I am curious if the manifests callback already helps with this problem?

Yeah, you should write your manifest file, then get it and compare the manifest with what you got

1 Like

We tried this.the compilers seem to run when you use mix to invoke any alias