-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8b4633
commit f1e0fff
Showing
11 changed files
with
364 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## mix igniter.new | ||
|
||
Provides `igniter.new` installer as an archive. | ||
|
||
To install from Hex, run: | ||
|
||
$ mix archive.install hex igniter_new | ||
|
||
To build and install it locally, | ||
ensure any previous archive versions are removed: | ||
|
||
$ mix archive.uninstall phx_new | ||
|
||
Then run: | ||
|
||
$ cd installer | ||
$ MIX_ENV=prod mix do archive.build, archive.install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
defmodule Mix.Tasks.Igniter.New do | ||
use Mix.Task | ||
|
||
@igniter_version Mix.Project.config()[:version] | ||
|
||
@shortdoc "Creates a new Igniter application" | ||
def run([name | _ ] = argv) do | ||
{options, argv, _errors} = OptionParser.parse(argv, | ||
strict: [install: :keep, local: :string, example: :boolean], | ||
aliases: [i: :install, l: :local, e: :example] | ||
) | ||
|
||
install = | ||
options[:install] | ||
|> List.wrap() | ||
|> Enum.join(",") | ||
|> String.split(",", trim: true) | ||
|
||
if File.exists?(name) do | ||
Mix.shell().error(""" | ||
The directory #{name} already exists. You must either: | ||
1. remove or move it | ||
2. If you are trying to modify an existing project add `{:igniter` to the project, if it is not | ||
already added, and then run `mix igniter.install #{Enum.join(install, ",")}` inside the project | ||
""") | ||
|
||
exit({:shutdown, 1}) | ||
end | ||
|
||
exit = Mix.shell().cmd("mix new #{Enum.join(argv, " ")}") | ||
|
||
if exit == 0 do | ||
version_requirement = | ||
if options[:local] do | ||
local = Path.join(["..", Path.relative_to_cwd(options[:local])]) | ||
"path: #{inspect(local)}" | ||
else | ||
inspect(version_requirement()) | ||
end | ||
|
||
File.cd!(name) | ||
|
||
contents = | ||
"mix.exs" | ||
|> File.read!() | ||
|
||
if String.contains?(contents, "{:igniter") do | ||
Mix.shell().info("It looks like the project already exists and igniter is already installed, not adding it to deps.") | ||
else | ||
new_contents = | ||
String.replace(contents, "defp deps do\n [\n", "defp deps do\n [\n{:igniter, #{version_requirement}}\n") | ||
|
||
File.write!("mix.exs", new_contents) | ||
end | ||
|
||
Mix.shell().cmd("mix deps.get") | ||
Mix.shell().cmd("mix compile") | ||
|
||
unless Enum.empty?(install) do | ||
example = | ||
if options[:example] do | ||
"--example" | ||
end | ||
Mix.shell().cmd("mix igniter.install #{Enum.join(install, ",")} --yes #{example}" |> IO.inspect()) | ||
end | ||
|
||
else | ||
Mix.shell().info("Aborting command because associated `mix new` command failed.") | ||
|
||
exit({:shutdown, 1}) | ||
end | ||
|
||
:ok | ||
end | ||
|
||
defp version_requirement do | ||
@igniter_version | ||
|> Version.parse!() | ||
|> case do | ||
%Version{major: 0, minor: minor} -> | ||
"~> 0.#{minor}" | ||
|
||
%Version{major: major} -> | ||
"~> #{major}.0" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Igniter.New.MixProject do | ||
use Mix.Project | ||
|
||
@version "0.1.0" | ||
@scm_url "https://github.com/ash-project/igniter" | ||
|
||
def project do | ||
[ | ||
app: :igniter_new, | ||
start_permanent: Mix.env() == :prod, | ||
version: @version, | ||
elixir: "~> 1.14", | ||
deps: deps(), | ||
package: [ | ||
maintainers: ["Zach Daniel"], | ||
licenses: ["MIT"], | ||
links: %{"GitHub" => @scm_url}, | ||
files: ~w(lib templates mix.exs README.md) | ||
], | ||
preferred_cli_env: [docs: :docs], | ||
source_url: @scm_url, | ||
docs: docs(), | ||
homepage_url: "https://www.ash-hq.org", | ||
description: """ | ||
Create a new mix project with igniter, and run igniter installers in one command! | ||
""" | ||
] | ||
end | ||
|
||
def deps do | ||
[ | ||
{:ex_doc, "~> 0.24", only: :docs} | ||
] | ||
end | ||
|
||
defp docs do | ||
[ | ||
source_url_pattern: "#{@scm_url}/blob/v#{@version}/installer/%{path}#L%{line}" | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
%{ | ||
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, | ||
"ex_doc": {:hex, :ex_doc, "0.34.0", "ab95e0775db3df71d30cf8d78728dd9261c355c81382bcd4cefdc74610bef13e", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "60734fb4c1353f270c3286df4a0d51e65a2c1d9fba66af3940847cc65a8066d7"}, | ||
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, | ||
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, | ||
"makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"}, | ||
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.