@@ -42,79 +42,94 @@ defmodule Mix.Tasks.Archive.Build do
42
42
* `--include-dot-files` - adds dot files from priv directory to the archive.
43
43
44
44
"""
45
- @ switches [ force: :boolean , compile: :boolean , output: :string , input: :string ,
46
- deps_check: :boolean , archives_check: :boolean , elixir_version_check: :boolean ,
47
- include_dot_files: :boolean ]
45
+ @ switches [
46
+ force: :boolean ,
47
+ compile: :boolean ,
48
+ output: :string ,
49
+ input: :string ,
50
+ deps_check: :boolean ,
51
+ archives_check: :boolean ,
52
+ elixir_version_check: :boolean ,
53
+ include_dot_files: :boolean
54
+ ]
48
55
49
56
def run ( args ) do
50
57
{ opts , _ } = OptionParser . parse! ( args , aliases: [ o: :output , i: :input ] , strict: @ switches )
51
58
52
- project = Mix.Project . get
59
+ project = Mix.Project . get ( )
53
60
54
61
if project && Keyword . get ( opts , :compile , true ) do
55
- Mix.Task . run :compile , args
62
+ Mix.Task . run ( :compile , args )
56
63
end
57
64
58
- source = cond do
59
- input = opts [ :input ] ->
60
- input
61
- project ->
62
- path = Mix.Project . app_path
63
- if elixir = Mix.Project . config [ :elixir ] do
64
- File . write Path . join ( path , ".elixir" ) , elixir
65
- else
66
- File . rm Path . join ( path , ".elixir" )
67
- end
68
- path
69
- true ->
70
- Mix . raise "Cannot create archive without input directory, " <>
71
- "please pass -i as an option"
72
- end
65
+ source =
66
+ cond do
67
+ input = opts [ :input ] ->
68
+ input
73
69
74
- project_config = Mix.Project . config
75
- target = cond do
76
- output = opts [ :output ] ->
77
- output
78
- project_config [ :app ] ->
79
- Mix.Local . name_for ( :archive , project_config )
80
- true ->
81
- Mix . raise "Cannot create archive without output file, " <>
82
- "please pass -o as an option"
83
- end
70
+ project ->
71
+ path = Mix.Project . app_path ( )
72
+
73
+ if elixir = Mix.Project . config ( ) [ :elixir ] do
74
+ File . write ( Path . join ( path , ".elixir" ) , elixir )
75
+ else
76
+ File . rm ( Path . join ( path , ".elixir" ) )
77
+ end
78
+
79
+ path
80
+
81
+ true ->
82
+ Mix . raise ( "Cannot create archive without input directory, please pass -i as an option" )
83
+ end
84
+
85
+ project_config = Mix.Project . config ( )
86
+
87
+ target =
88
+ cond do
89
+ output = opts [ :output ] ->
90
+ output
91
+
92
+ project_config [ :app ] ->
93
+ Mix.Local . name_for ( :archive , project_config )
94
+
95
+ true ->
96
+ Mix . raise ( "Cannot create archive without output file, please pass -o as an option" )
97
+ end
84
98
85
99
unless File . dir? ( source ) do
86
- Mix . raise "Expected archive source #{ inspect source } to be a directory"
100
+ Mix . raise ( "Expected archive source #{ inspect ( source ) } to be a directory" )
87
101
end
88
102
89
103
create ( source , target , Keyword . get ( opts , :include_dot_files , false ) )
90
104
91
- Mix . shell . info "Generated archive #{ inspect target } with MIX_ENV=#{ Mix . env } "
105
+ Mix . shell ( ) . info ( "Generated archive #{ inspect ( target ) } with MIX_ENV=#{ Mix . env ( ) } " )
92
106
:ok
93
107
end
94
108
95
109
defp create ( source , target , include_dot_files? ) do
96
110
source_path = Path . expand ( source )
97
111
target_path = Path . expand ( target )
98
- dir = Mix.Local . archive_name ( target_path ) |> String . to_charlist
99
- { :ok , _ } = :zip . create ( String . to_charlist ( target_path ) ,
100
- files_to_add ( source_path , dir , include_dot_files? ) )
112
+ dir = Mix.Local . archive_name ( target_path ) |> String . to_charlist ( )
113
+ file_list = files_to_add ( source_path , dir , include_dot_files? )
114
+ { :ok , _ } = :zip . create ( String . to_charlist ( target_path ) , file_list )
101
115
:ok
102
116
end
103
117
104
118
defp files_to_add ( path , dir , include_dot_files? ) do
105
- File . cd! path , fn ->
119
+ File . cd! ( path , fn ->
106
120
evsn = Path . wildcard ( ".elixir" )
107
121
ebin = Path . wildcard ( "ebin/*.{beam,app}" )
108
122
priv = Path . wildcard ( "priv/**/*" , match_dot: include_dot_files? )
109
123
110
- Enum . reduce evsn ++ ebin ++ priv , [ ] , fn ( f , acc ) ->
124
+ Enum . reduce ( evsn ++ ebin ++ priv , [ ] , fn f , acc ->
111
125
case File . read ( f ) do
112
126
{ :ok , bin } ->
113
- [ { Path . join ( dir , f ) |> String . to_charlist , bin } | acc ]
127
+ [ { Path . join ( dir , f ) |> String . to_charlist ( ) , bin } | acc ]
128
+
114
129
{ :error , _ } ->
115
130
acc
116
131
end
117
- end
118
- end
132
+ end )
133
+ end )
119
134
end
120
135
end
0 commit comments