Skip to content

Commit

Permalink
Format for elixir 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
aforward committed Jan 29, 2018
1 parent 1f7dc82 commit 8a517a3
Show file tree
Hide file tree
Showing 26 changed files with 293 additions and 280 deletions.
3 changes: 3 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
46 changes: 22 additions & 24 deletions lib/mix/tasks/bin/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ defmodule Mix.Tasks.Version.Bin.Db do
@shortdoc "Create 'rel/commands' helper scripts for managing database backup / restore"
def run([]), do: run([nil, nil])
def run([backup_root]), do: run([backup_root, nil])
def run([backup_root, dbname]) do

def run([backup_root, dbname]) do
[
"./rel/commands",
"./rel/commands"
]
|> Enum.each(fn dirname ->
:ok = dirname |> Path.expand |> File.mkdir_p!
end)
:ok = dirname |> Path.expand() |> File.mkdir_p!()
end)

appname = Mix.Project.config[:app]
appname = Mix.Project.config()[:app]
default_root = "/src/#{appname}backup"
backup_root = backup_root || default_root
dbname = dbname || appname
Expand Down Expand Up @@ -49,25 +49,25 @@ defmodule Mix.Tasks.Version.Bin.Db do
"""
|> write!("./rel/commands/restore")


[
"./rel/commands/backup",
"./rel/commands/restore",
"./rel/commands/restore"
]
|> Enum.each(fn filename ->
:ok = filename
|> Path.expand
|> File.chmod(0o755)
end)
:ok =
filename
|> Path.expand()
|> File.chmod(0o755)
end)

IO.puts "Installed the following scripts into ./rel/commands"
IO.puts " + backup \# Backup your database (named #{appname})"
IO.puts " + restore \# Restore your database (named #{appname})"
IO.puts ""
IO.puts("Installed the following scripts into ./rel/commands")
IO.puts(" + backup \# Backup your database (named #{appname})")
IO.puts(" + restore \# Restore your database (named #{appname})")
IO.puts("")

IO.puts "To enable those to be part of the release,"
IO.puts "then ensure you update your ./rel/config.exs with:"
IO.puts ""
IO.puts("To enable those to be part of the release,")
IO.puts("then ensure you update your ./rel/config.exs with:")
IO.puts("")

example = """
release :#{appname} do
Expand All @@ -79,13 +79,11 @@ defmodule Mix.Tasks.Version.Bin.Db do
end
"""

IO.puts example
IO.puts ""

IO.puts(example)
IO.puts("")
end

defp write!(content, relative_name) do
File.write!(relative_name |> Path.expand, content)
File.write!(relative_name |> Path.expand(), content)
end

end
end
59 changes: 27 additions & 32 deletions lib/mix/tasks/bin/ff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ defmodule Mix.Tasks.Version.Bin.Ff do

@shortdoc "Add a FeatureFlags (FF) GenServer with release helper scripts to enable/disable them"
def run(_) do

[
"./rel/commands",
"./rel/commands"
]
|> Enum.each(fn dirname ->
:ok = dirname |> Path.expand |> File.mkdir_p!
end)

appname = Mix.Project.config[:app]
module_name = appname |> Atom.to_string |> Macro.camelize
:ok = dirname |> Path.expand() |> File.mkdir_p!()
end)

appname = Mix.Project.config()[:app]
module_name = appname |> Atom.to_string() |> Macro.camelize()

"""
defmodule #{module_name}.FeatureFlags do
Expand Down Expand Up @@ -90,7 +88,6 @@ defmodule Mix.Tasks.Version.Bin.Ff do
"""
|> write!("./lib/#{appname}/feature_flags.ex")


"""
#!/bin/bash
bin/#{appname} rpc Elixir.#{module_name}.FeatureFlags enable "$1"
Expand All @@ -103,22 +100,22 @@ defmodule Mix.Tasks.Version.Bin.Ff do
"""
|> write!("./rel/commands/disable")


[
"./rel/commands/enable",
"./rel/commands/disable",
"./rel/commands/disable"
]
|> Enum.each(fn filename ->
:ok = filename
|> Path.expand
|> File.chmod(0o755)
end)

IO.puts "Installed several release scripts into ./bin/run and ./bin/package"
IO.puts "To enable ./rel/commands/enable and ./rel/commands/disable to be"
IO.puts "part of the release, then ensure you update your ./rel/config.exs with:"
IO.puts ""
IO.puts ""
:ok =
filename
|> Path.expand()
|> File.chmod(0o755)
end)

IO.puts("Installed several release scripts into ./bin/run and ./bin/package")
IO.puts("To enable ./rel/commands/enable and ./rel/commands/disable to be")
IO.puts("part of the release, then ensure you update your ./rel/config.exs with:")
IO.puts("")
IO.puts("")

example = """
release :#{appname} do
Expand All @@ -130,19 +127,17 @@ defmodule Mix.Tasks.Version.Bin.Ff do
end
"""

IO.puts example
IO.puts ""
IO.puts "To enable a feature flag 'brb' (for example) you would run the following:"
IO.puts " ./bin/#{appname} enable brb"
IO.puts ""
IO.puts "To later disable that flag you would run the following:"
IO.puts " ./bin/#{appname} disable brb"
IO.puts ""

IO.puts(example)
IO.puts("")
IO.puts("To enable a feature flag 'brb' (for example) you would run the following:")
IO.puts(" ./bin/#{appname} enable brb")
IO.puts("")
IO.puts("To later disable that flag you would run the following:")
IO.puts(" ./bin/#{appname} disable brb")
IO.puts("")
end

defp write!(content, relative_name) do
File.write!(relative_name |> Path.expand, content)
File.write!(relative_name |> Path.expand(), content)
end

end
end
51 changes: 22 additions & 29 deletions lib/mix/tasks/bin/release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ defmodule Mix.Tasks.Version.Bin.Release do

@shortdoc "Initialize and create some 'bin' helper scripts for managing releases"
def run([]), do: run([nil])
def run([release_root]) do

def run([release_root]) do
unless File.exists?("./rel/config.exs") do
Mix.Task.run("release.init", [])
end

[
"./bin/run",
"./bin/package",
"./rel/commands",
"./rel/commands"
]
|> Enum.each(fn dirname ->
:ok = dirname |> Path.expand |> File.mkdir_p!
end)
:ok = dirname |> Path.expand() |> File.mkdir_p!()
end)

appname = Mix.Project.config[:app]
appname = Mix.Project.config()[:app]
default_root = "/src/#{appname}rel"
release_root = release_root || default_root
module_name = appname |> Atom.to_string |> Macro.camelize

module_name = appname |> Atom.to_string() |> Macro.camelize()

"""
defmodule #{module_name}.ReleaseTasks do
Expand Down Expand Up @@ -87,7 +86,6 @@ defmodule Mix.Tasks.Version.Bin.Release do
"""
|> write!("./lib/#{appname}/release_tasks.ex")


"""
#!/bin/bash
mix deps.unlock --all && \\
Expand All @@ -104,7 +102,6 @@ defmodule Mix.Tasks.Version.Bin.Release do
"""
|> write!("./bin/package/release")


"""
#!/bin/bash
VERSION=$(mix version.current)
Expand All @@ -129,7 +126,6 @@ defmodule Mix.Tasks.Version.Bin.Release do
"""
|> write!("./bin/package/retain")


"""
#!/bin/bash
Expand All @@ -141,7 +137,6 @@ defmodule Mix.Tasks.Version.Bin.Release do
"""
|> write!("./bin/run/rel")


"""
#!/bin/bash
Expand Down Expand Up @@ -175,7 +170,6 @@ defmodule Mix.Tasks.Version.Bin.Release do
"""
|> write!("./bin/run/debug")


[
"./bin/package/prerelease",
"./bin/package/release",
Expand All @@ -184,19 +178,20 @@ defmodule Mix.Tasks.Version.Bin.Release do
"./bin/run/launch",
"./bin/run/debug",
"./rel/commands/clear_cache",
"./rel/commands/migrate",
"./rel/commands/migrate"
]
|> Enum.each(fn filename ->
:ok = filename
|> Path.expand
|> File.chmod(0o755)
end)

IO.puts "Installed several release scripts into ./bin/run and ./bin/package"
IO.puts "To enable ./rel/commands/clear_cache and ./rel/commands/migrate to be"
IO.puts "part of the release, then ensure you update your ./rel/config.exs with:"
IO.puts ""
IO.puts ""
:ok =
filename
|> Path.expand()
|> File.chmod(0o755)
end)

IO.puts("Installed several release scripts into ./bin/run and ./bin/package")
IO.puts("To enable ./rel/commands/clear_cache and ./rel/commands/migrate to be")
IO.puts("part of the release, then ensure you update your ./rel/config.exs with:")
IO.puts("")
IO.puts("")

example = """
release :#{appname} do
Expand All @@ -208,13 +203,11 @@ defmodule Mix.Tasks.Version.Bin.Release do
end
"""

IO.puts example
IO.puts ""

IO.puts(example)
IO.puts("")
end

defp write!(content, relative_name) do
File.write!(relative_name |> Path.expand, content)
File.write!(relative_name |> Path.expand(), content)
end

end
end
9 changes: 4 additions & 5 deletions lib/mix/tasks/current.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ defmodule Mix.Tasks.Version.Current do
def run(args) do
args
|> calc
|> IO.puts
|> IO.puts()
end

@shortdoc "Calculate the current version"
def calc(_ \\ nil) do
"mix.exs"
|> File.read
|> invoke(fn ({:ok, content}) -> content end)
|> File.read()
|> invoke(fn {:ok, content} -> content end)
|> String.split("\n")
|> Enum.map(&find_version/1)
|> Enum.reject(&is_nil/1)
Expand Down Expand Up @@ -44,5 +44,4 @@ defmodule Mix.Tasks.Version.Current do
:error -> nil
end
end

end
end
Loading

0 comments on commit 8a517a3

Please sign in to comment.