-
Notifications
You must be signed in to change notification settings - Fork 5
/
distillery-plugin.sh
executable file
·81 lines (64 loc) · 1.56 KB
/
distillery-plugin.sh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
usage ()
{
echo "Usage : $(basename "$0") project-name"
echo "Creates a Distillery rel/digest_plugins.exs file updates rel/config.exs to populate priv/static for deployments."
exit
}
if [ "$#" -ne 1 ]; then
usage
fi
run () {
CMD=$(cat <<EOF
defmodule ${1}.PhoenixDigestTask do
use Mix.Releases.Plugin
def before_assembly(%Release{} = _release) do
info "before assembly!"
# NOTE: If your app has brunch, you can enable this code.
case System.cmd("npm", ["install"]) do
{output, 0} ->
case System.cmd("npm", ["run", "deploy"]) do
{output, 0} ->
info output
Mix.Task.run("phoenix.digest")
nil
{output, error_code} ->
{:error, output, error_code}
end
{output, error_code} ->
{:erro, output, error_code}
end
end
def after_assembly(%Release{} = _release) do
info "after assembly!"
nil
end
def before_package(%Release{} = _release) do
info "before package!"
nil
end
def after_package(%Release{} = _release) do
info "after package!"
nil
end
def after_cleanup(%Release{} = _release) do
info "after cleanup!"
nil
end
end
EOF
)
echo "Generating plugin.."
mkdir -p rel/plugins
echo "${CMD}" > rel/plugins/digest_plugin.exs
echo "Updating rel/config.exs.."
PREV_CONFIG=$(cat rel/config.exs)
CONFIG=$(cat <<EOF
Code.eval_file(Path.join([__DIR__, "rel", "plugins", "digest_plugin.exs"]))
${PREV_CONFIG}
EOF
)
echo "${CONFIG}" > rel/config.exs
echo "Done!"
}
run $1