mirror of
https://github.com/ash-project/igniter.git
synced 2024-09-17 03:52:51 +12:00
improvement: support --with
option in igniter.new
This commit is contained in:
parent
62ddc0bb4d
commit
e9bf1ecf8e
4 changed files with 76 additions and 53 deletions
|
@ -1,7 +1,7 @@
|
||||||
spark_locals_without_parens = [attributes: 1, decrypt_by_default: 1, on_decrypt: 1, vault: 1]
|
spark_locals_without_parens = [attributes: 1, decrypt_by_default: 1, on_decrypt: 1, vault: 1]
|
||||||
|
|
||||||
[
|
[
|
||||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
|
inputs: ["{mix,.formatter}.exs", "{config,lib,test,installer}/**/*.{ex,exs}"],
|
||||||
locals_without_parens: spark_locals_without_parens,
|
locals_without_parens: spark_locals_without_parens,
|
||||||
export: [
|
export: [
|
||||||
locals_without_parens: spark_locals_without_parens
|
locals_without_parens: spark_locals_without_parens
|
||||||
|
|
14
.github/dependabot.yml
vendored
14
.github/dependabot.yml
vendored
|
@ -1,6 +1,12 @@
|
||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
- package-ecosystem: mix
|
- package-ecosystem: mix
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "daily"
|
interval: weekly
|
||||||
|
day: thursday
|
||||||
|
groups:
|
||||||
|
production-dependencies:
|
||||||
|
dependency-type: production
|
||||||
|
dev-dependencies:
|
||||||
|
dependency-type: development
|
||||||
|
|
14
README.md
14
README.md
|
@ -31,14 +31,22 @@ Igniter can be added to an existing elixir project by adding it to your dependen
|
||||||
|
|
||||||
You can also generate new projects with igniter preinstalled, and run installers in the same command.
|
You can also generate new projects with igniter preinstalled, and run installers in the same command.
|
||||||
|
|
||||||
|
First, install the archive:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
mix archive.install hex igniter_new
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can run `mix igniter.new`
|
||||||
|
|
||||||
```
|
```
|
||||||
mix igniter.new app_name --install ash
|
mix igniter.new app_name --install ash
|
||||||
```
|
```
|
||||||
|
|
||||||
To use this command, install the archive:
|
Or if you want to use a different project creator, specify the mix task name with the `--with` flag. Any arguments will be passed through to that task, with the exception of `--install` and `--example`.
|
||||||
|
|
||||||
```elixir
|
```
|
||||||
mix archive.install hex igniter_new
|
mix igniter.new app_name --install ash --with phx.new --no-ecto
|
||||||
```
|
```
|
||||||
|
|
||||||
## Patterns
|
## Patterns
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule Mix.Tasks.Igniter.New do
|
||||||
|
|
||||||
* `--install` - A comma-separated list of dependencies to install using `mix igniter.install` after creating the project.
|
* `--install` - A comma-separated list of dependencies to install using `mix igniter.install` after creating the project.
|
||||||
* `--example` - Request example code to be added to the project when installing packages.
|
* `--example` - Request example code to be added to the project when installing packages.
|
||||||
|
* `--with` - The command to use instead of `new`, i.e `phx.new`
|
||||||
"""
|
"""
|
||||||
@shortdoc "Creates a new Igniter application"
|
@shortdoc "Creates a new Igniter application"
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
@ -15,11 +16,20 @@ defmodule Mix.Tasks.Igniter.New do
|
||||||
@igniter_version Mix.Project.config()[:version]
|
@igniter_version Mix.Project.config()[:version]
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run([name | _ ] = argv) do
|
def run([name | _] = argv) do
|
||||||
{options, argv, _errors} = OptionParser.parse(argv,
|
{options, argv, _errors} =
|
||||||
strict: [install: :keep, local: :string, example: :boolean],
|
OptionParser.parse(argv,
|
||||||
aliases: [i: :install, l: :local, e: :example]
|
strict: [install: :keep, local: :string, example: :boolean, with: :string],
|
||||||
)
|
aliases: [i: :install, l: :local, e: :example, w: :with]
|
||||||
|
)
|
||||||
|
|
||||||
|
install_with = options[:with] || "new"
|
||||||
|
|
||||||
|
unless install_with in ["phx.new", "new"] do
|
||||||
|
if String.match?(install_with, ~r/\s/) do
|
||||||
|
raise ArgumentError, "The --with option must not contain any spaces, got: #{install_with}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
install =
|
install =
|
||||||
options[:install]
|
options[:install]
|
||||||
|
@ -38,49 +48,48 @@ defmodule Mix.Tasks.Igniter.New do
|
||||||
exit({:shutdown, 1})
|
exit({:shutdown, 1})
|
||||||
end
|
end
|
||||||
|
|
||||||
exit = Mix.shell().cmd("mix new #{Enum.join(argv, " ")}")
|
Mix.Task.run(install_with, argv)
|
||||||
|
|
||||||
if exit == 0 do
|
version_requirement =
|
||||||
version_requirement =
|
if options[:local] do
|
||||||
if options[:local] do
|
local = Path.join(["..", Path.relative_to_cwd(options[:local])])
|
||||||
local = Path.join(["..", Path.relative_to_cwd(options[:local])])
|
"path: #{inspect(local)}, override: true"
|
||||||
"path: #{inspect(local)}, override: true"
|
else
|
||||||
else
|
inspect(version_requirement())
|
||||||
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
|
||||||
|
# the spaces are required here to avoid the need for a format
|
||||||
|
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
|
||||||
|
|
||||||
|
unless Enum.empty?(install) do
|
||||||
|
Mix.shell().cmd("mix deps.get")
|
||||||
|
Mix.shell().cmd("mix compile")
|
||||||
|
|
||||||
|
example =
|
||||||
|
if options[:example] do
|
||||||
|
"--example"
|
||||||
end
|
end
|
||||||
|
|
||||||
File.cd!(name)
|
Mix.shell().cmd("mix igniter.install #{Enum.join(install, ",")} --yes #{example}")
|
||||||
|
|
||||||
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
|
|
||||||
# the spaces are required here to avoid the need for a format
|
|
||||||
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
|
|
||||||
|
|
||||||
unless Enum.empty?(install) do
|
|
||||||
Mix.shell().cmd("mix deps.get")
|
|
||||||
Mix.shell().cmd("mix compile")
|
|
||||||
|
|
||||||
example =
|
|
||||||
if options[:example] do
|
|
||||||
"--example"
|
|
||||||
end
|
|
||||||
|
|
||||||
Mix.shell().cmd("mix igniter.install #{Enum.join(install, ",")} --yes #{example}")
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
Mix.shell().info("Aborting command because associated `mix new` command failed.")
|
|
||||||
|
|
||||||
exit({:shutdown, 1})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
|
|
Loading…
Reference in a new issue