Skip to content

Commit a34999e

Browse files
committed
avoid keeping the app running while editing the map
1 parent afc48a8 commit a34999e

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

lib/mix/tasks/edit_map.ex renamed to lib/mix/tasks/velo.map.edit.ex

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule Mix.Tasks.EditMap do
1+
defmodule Mix.Tasks.Velo.Map.Edit do
22
use Mix.Task
33
alias Mix.Tasks.Velo.Videos
44
@requirements ["app.start"]
@@ -8,27 +8,36 @@ defmodule Mix.Tasks.EditMap do
88
@session_path "data/cache/map_session.jos"
99
@route_colors_path "data/cache/route_colors.mapcss"
1010

11-
@shortdoc "Prepares data for viewing and opens map in JOSM"
11+
def run(["postprocess"]) do
12+
IO.puts("Cleaning up map.osm…")
13+
remove_osm_history()
14+
IO.puts("Updating GPX…")
15+
Mix.Tasks.Velo.Gpx.Generate.run([])
16+
end
17+
18+
@shortdoc "Allows editing map in JOSM"
1219
def run(_) do
1320
generate_mapcss()
1421
write_josm_session()
1522

16-
{_stream, 0} =
17-
System.cmd(
18-
"josm",
23+
commands =
24+
[
25+
["export", "JAVA_OPTS=-Djosm.home=#{Path.absname(@josm_home)}"],
1926
[
27+
"josm",
2028
"--offline=osm_api,josm_website,certificates",
2129
"--load-preferences=#{Path.absname(@josm_default_prefs)}",
2230
@session_path
2331
],
24-
env: [{"JAVA_OPTS", "-Djosm.home=#{Path.absname(@josm_home)}"}]
25-
)
26-
27-
remove_osm_history()
28-
29-
# run in extra process to ensure we recompile after map update
30-
IO.puts("Updating GPX…")
31-
{_stream, 0} = System.cmd("mix", ["velo.gpx.generate"], into: IO.stream(:stdio, :line))
32+
["mix", "velo.map.edit", "postprocess"]
33+
]
34+
|> Enum.map(&Util.cli_printer/1)
35+
|> Enum.join(" && ")
36+
37+
# ideally we could just `exec`, but BEAM doesn't expose that without NIFs :()
38+
bash = "(#{commands}) &"
39+
IO.puts("running: #{bash}")
40+
bash |> String.to_charlist() |> :os.cmd() |> IO.puts()
3241
end
3342

3443
defp remove_osm_history() do

0 commit comments

Comments
 (0)