简体   繁体   English

编写一个在deps.get之后运行的Mix任务

[英]Write a Mix task that runs after deps.get

Is there a way to hook into Elixir's Mix built in tasks to execute a task after another one has completed? 有没有办法挂钩到Elixir的内置任务中,以便在另一个任务完成后执行任务?

I know you can do something similar to this. 我知道您可以做类似的事情。

defmodule Mix.Tasks.Other.Get
  use Mix.Task

  @shortdoc "Other dependencies?"
  def run(_) do
    Mix.Task.run("deps.get")
  end
end

But I kindof want a task to run right after mix deps.get considering using make to wrap the commands that make the most sense. 但是我有点想让任务在mix deps.get之后立即运行,考虑使用make来包装最有意义的命令。 (ie make deps which would run both mix deps.get then mix other.get ) (即make deps将同时运行两个mix deps.get然后mix other.get

You can use a Mix alias for that: 您可以为此使用Mix别名

defmodule MyApp.MixProject do
  use Mix.Project

  def project do
    [
      app: :my_app,
      version: "1.0.0",
      aliases: aliases()
    ]
  end

  defp aliases do
    [
      "deps.get": ["deps.get", "custom.task"]
    ]
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM