Packages
exrm
1.0.8
1.0.8
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc8
1.0.0-rc7
1.0.0-rc6
1.0.0-rc5
1.0.0-rc4
1.0.0-rc3
0.19.9
0.19.8
0.19.7
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.8
0.18.7
0.18.6
0.18.5
0.18.4
0.18.3
0.18.2
0.18.1
0.18.0
0.17.3
0.17.2
0.17.1
0.17.0
0.16.0
0.15.3
0.15.2
0.15.1
0.15.0
0.14.17
0.14.16
0.14.15
0.14.14
0.14.13
0.14.12
0.14.11
0.14.10
0.14.9
0.14.8
0.14.7
0.14.6
0.14.5
0.14.3
0.14.2
0.14.1
0.14.0
0.12.12
0.12.11
0.12.10
0.12.9
0.12.8
0.12.7
0.12.6
0.12.5
0.12.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.3
0.10.1
0.10.0
0.9.2
0.9.1
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.7
Exrm, or Elixir Release Manager, provides mix tasks for building, upgrading, and controlling release packages for your application.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/release.clean.ex
defmodule Mix.Tasks.Release.Clean do
@moduledoc """
Clean up any release-related files.
## Examples
# Cleans the release for the current version of the project
mix release.clean
# Remove all files generated by exrm, including releases
mix release.clean --implode
# Implode, but do not confirm (DANGEROUS)
mix release.clean --implode --no-confirm
"""
@shortdoc "Clean up any release-related files"
use Mix.Task
alias ReleaseManager.Utils.Logger
import ReleaseManager.Utils
def run(args) do
if Mix.Project.umbrella? do
config = [build_path: Mix.Project.build_path]
for %Mix.Dep{app: app, opts: opts} <- Mix.Dep.Umbrella.loaded do
Mix.Project.in_project(app, opts[:path], config, fn _ -> do_run(args) end)
end
else
do_run(args)
end
end
def do_run(args) do
app = Mix.Project.config |> Keyword.get(:app)
version = Mix.Project.config |> Keyword.get(:version)
Logger.debug "Removing release files for #{app}-#{version}..."
cond do
"--implode" in args ->
if "--no-confirm" in args or confirm_implode?(app) do
do_cleanup :all
execute_after_hooks(args)
Logger.info "All release files for #{app}-#{version} were removed successfully!"
end
true ->
do_cleanup :build
execute_after_hooks(args)
Logger.info "The release for #{app}-#{version} has been removed."
end
end
# Clean release build
def do_cleanup(:build) do
project = Mix.Project.config |> Keyword.get(:app) |> Atom.to_string
version = Mix.Project.config |> Keyword.get(:version)
build = Path.absname("../prod", Mix.Project.build_path)
release = rel_dest_path [project, "releases", version]
releases = rel_dest_path [project, "releases", "RELEASES"]
start_erl = rel_dest_path [project, "releases", "start_erl.data"]
lib = rel_dest_path [project, "lib", "#{project}-#{version}"]
relup = rel_dest_path [project, "relup"]
if File.exists?(release), do: File.rm_rf!(release)
if File.exists?(releases), do: File.rm_rf!(releases)
if File.exists?(start_erl), do: File.rm_rf!(start_erl)
if File.exists?(lib), do: File.rm_rf!(lib)
if File.exists?(relup), do: File.rm_rf!(relup)
if Mix.env != :prod && File.exists?(build) do
build
|> File.ls!
|> Enum.map(fn dir -> build |> Path.join(dir) end)
|> Enum.map(&File.rm_rf!/1)
end
end
# Clean up the template files for release generation
def do_cleanup(:relfiles) do
rel_files = rel_file_dest_path
if File.exists?(rel_files), do: File.rm_rf!(rel_files)
end
# Clean up everything
def do_cleanup(:all) do
# Execute other clean tasks
do_cleanup :build
# Remove release folder
rel = rel_dest_path
if File.exists?(rel), do: File.rm_rf!(rel)
end
defp execute_after_hooks(args) do
plugins = ReleaseManager.Plugin.load_all
Enum.each plugins, fn plugin ->
try do
plugin.after_cleanup(args)
rescue
exception ->
stacktrace = System.stacktrace
Logger.error "Failed to execute after_cleanup hook for #{plugin}!"
reraise exception, stacktrace
end
end
end
defp confirm_implode?(app) do
IO.puts IO.ANSI.yellow
msg = """
THIS WILL REMOVE ALL RELEASES AND RELATED CONFIGURATION FOR #{app |> Atom.to_string |> String.upcase}!
Are you absolutely sure you want to proceed?
"""
answer = IO.gets(msg <> " [Yn]: ") |> String.rstrip(?\n)
IO.puts IO.ANSI.reset
answer =~ ~r/^(Y(es)?)?$/i
end
end