1
- defmodule Mix.Tasks.EditMap do
1
+ defmodule Mix.Tasks.Velo.Map.Edit do
2
2
use Mix.Task
3
3
alias Mix.Tasks.Velo.Videos
4
4
@ requirements [ "app.start" ]
@@ -8,27 +8,36 @@ defmodule Mix.Tasks.EditMap do
8
8
@ session_path "data/cache/map_session.jos"
9
9
@ route_colors_path "data/cache/route_colors.mapcss"
10
10
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"
12
19
def run ( _ ) do
13
20
generate_mapcss ( )
14
21
write_josm_session ( )
15
22
16
- { _stream , 0 } =
17
- System . cmd (
18
- "josm" ,
23
+ commands =
24
+ [
25
+ [ "export" , "JAVA_OPTS=-Djosm.home= #{ Path . absname ( @ josm_home ) } " ] ,
19
26
[
27
+ "josm" ,
20
28
"--offline=osm_api,josm_website,certificates" ,
21
29
"--load-preferences=#{ Path . absname ( @ josm_default_prefs ) } " ,
22
30
@ session_path
23
31
] ,
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 ( )
32
41
end
33
42
34
43
defp remove_osm_history ( ) do
0 commit comments