defmodule Mix.Tasks.Mob.Deploy do use Mix.Task @shortdoc "Build and deploy to all connected mob devices" @moduledoc """ Compiles the project then pushes BEAM files to all connected Android devices and iOS simulators. ## Modes **Fast deploy** (default) — push BEAMs + restart. Use this for day-to-day Elixir code changes. Requires the native app already installed on device. mix mob.deploy **Full deploy** — build native binary + install APK/app + push BEAMs. Use this the first time, or after changes to native C/Java/Swift code. mix mob.deploy --native ## Options * `--native` — build native binaries before pushing BEAMs * `--no-restart` — push BEAMs but don't restart the app """ @switches [native: :boolean, restart: :boolean] @impl Mix.Task def run(args) do {opts, _, _} = OptionParser.parse(args, switches: @switches) restart = Keyword.get(opts, :restart, true) native = Keyword.get(opts, :native, false) IO.puts("") Mix.Task.run("compile") IO.puts("\n#{IO.ANSI.cyan()}Deploying to devices...#{IO.ANSI.reset()}\n") if native do MobDev.NativeBuild.build_all() end {deployed, failed} = MobDev.Deployer.deploy_all(restart: restart) if deployed == [] and failed == [] do IO.puts("#{IO.ANSI.yellow()}No devices found.#{IO.ANSI.reset()}") IO.puts("Try: mix mob.devices to diagnose connection issues") else if deployed != [] do IO.puts("\n#{IO.ANSI.green()}Deployed to #{length(deployed)} device(s)#{IO.ANSI.reset()}") if restart do IO.puts("Apps restarted. Run #{IO.ANSI.cyan()}mix mob.connect#{IO.ANSI.reset()} to open IEx.") else IO.puts("BEAMs pushed. In IEx: #{IO.ANSI.cyan()}nl(MyModule)#{IO.ANSI.reset()} to hot-load.") end end if failed != [] do IO.puts("\n#{IO.ANSI.red()}Failed on #{length(failed)} device(s)#{IO.ANSI.reset()}") Enum.each(failed, fn d -> IO.puts(" ✗ #{d.name || d.serial}: #{d.error}") end) end end end end