Packages
mob_dev
0.2.0
0.6.23
0.6.22
0.6.21
0.6.20
0.6.19
0.6.18
0.6.17
0.6.16
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.0
0.3.37
0.3.35
0.3.34
0.3.33
0.3.28
0.3.26
0.3.23
0.3.21
0.3.19
0.3.18
0.3.17
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.18
0.2.17
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0
Development tooling for the Mob mobile framework
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/mob.deploy.ex
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, android: :boolean, ios: :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)
platforms = resolve_platforms(opts)
IO.puts("")
if native do
IO.puts("Fetching dependencies...")
mix = System.find_executable("mix")
System.cmd(mix, ["deps.get"], into: IO.stream())
end
Mix.Task.run("compile")
IO.puts("\n#{IO.ANSI.cyan()}Deploying to devices...#{IO.ANSI.reset()}\n")
if native do
MobDev.NativeBuild.build_all(platforms: platforms)
end
{deployed, failed} = MobDev.Deployer.deploy_all(restart: restart, platforms: platforms)
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
defp resolve_platforms(opts) do
android = opts[:android]
ios = opts[:ios]
cond do
android && ios -> [:android, :ios]
android -> [:android]
ios ->
if macos?() do
[:ios]
else
IO.puts("#{IO.ANSI.yellow()}Warning: --ios is only supported on macOS. Skipping iOS.#{IO.ANSI.reset()}")
[]
end
macos?() -> [:android, :ios]
true -> [:android]
end
end
defp macos?, do: match?({:unix, :darwin}, :os.type())
end