-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
phx.digest.ex
59 lines (46 loc) · 1.86 KB
/
phx.digest.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
defmodule Mix.Tasks.Phx.Digest do
use Mix.Task
@default_input_path "priv/static"
@shortdoc "Digests and compresses static files"
@recursive true
@moduledoc """
Digests and compresses static files.
mix phx.digest
mix phx.digest priv/static -o /www/public
The first argument is the path where the static files are located. The
`-o` option indicates the path that will be used to save the digested and
compressed files.
If no path is given, it will use `priv/static` as the input and output path.
The output folder will contain:
* the original file
* the file compressed with gzip
* a file containing the original file name and its digest
* a compressed file containing the file name and its digest
* a cache manifest file
Example of generated files:
* app.js
* app.js.gz
* app-eb0a5b9302e8d32828d8a73f137cc8f0.js
* app-eb0a5b9302e8d32828d8a73f137cc8f0.js.gz
* cache_manifest.json
"""
@doc false
def run(all_args) do
{opts, args, _} = OptionParser.parse(all_args, switches: [output: :string], aliases: [o: :output])
input_path = List.first(args) || @default_input_path
output_path = opts[:output] || input_path
Mix.Task.run "deps.loadpaths", all_args
{:ok, _} = Application.ensure_all_started(:phoenix)
case Phoenix.Digester.compile(input_path, output_path) do
:ok ->
# We need to call build structure so everything we have
# generated into priv is copied to _build in case we have
# build_embedded set to true. In case it's not true,
# build structure is mostly a no-op, so we are fine.
Mix.Project.build_structure()
Mix.shell().info [:green, "Check your digested files at #{inspect output_path}"]
{:error, :invalid_path} ->
Mix.shell().error "The input path #{inspect input_path} does not exist"
end
end
end