igniter/README.md

84 lines
3.5 KiB
Markdown
Raw Permalink Normal View History

2024-06-13 10:36:32 +12:00
<img src="https://github.com/ash-project/igniter/blob/main/logos/igniter-logo-small.png?raw=true#gh-light-mode-only" alt="Logo Light" width="250">
<img src="https://github.com/ash-project/igniter/blob/main/logos/igniter-logo-small.png?raw=true#gh-dark-mode-only" alt="Logo Dark" width="250">
2024-05-28 15:30:41 +12:00
2024-06-13 10:36:32 +12:00
[![CI](https://github.com/ash-project/igniter/actions/workflows/elixir.yml/badge.svg)](https://github.com/ash-project/igniter/actions/workflows/elixir.yml)
2024-06-14 00:14:28 +12:00
[![Hex version badge](https://img.shields.io/hexpm/v/igniter.svg)](https://hex.pm/packages/igniter)
2024-05-30 02:28:08 +12:00
[![Hexdocs badge](https://img.shields.io/badge/docs-hexdocs-purple)](https://hexdocs.pm/igniter)
2024-06-06 02:12:07 +12:00
# Igniter
Igniter is a code generation and project patching framework.
2024-06-13 12:54:44 +12:00
For library authors, this is a tool kit for writing smarter generators that can semantically modify existing files, and all sorts of useful tools for doing so.
For end-users, this means `mix igniter.install <package>`, which will _add it to your mix.exs automatically_ and then run that library's installer if it has one. Even when libraries don't have an installer, or use igniter, this behavior makes it useful to keep around.
## State of the project
This project is in early beta. There is _so much to add_! There are lots of DX/UX things to improve, but it does already provide some great utility. Contributions welcome!
## Limitations
Right now, all files that are touched are formatted in their entirety. This may be a deal breaker for some users. I believe that we can solve this without changing the fundemental design of the project, but it is not a high priority in the early stages.
2024-06-06 02:12:07 +12:00
## Installation
Igniter can be added to an existing elixir project by adding it to your dependencies:
```elixir
{:igniter, "~> 0.1"}
2024-06-06 02:12:07 +12:00
```
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`
2024-06-06 02:12:07 +12:00
```
mix igniter.new app_name --install ash
```
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`.
2024-06-13 12:41:07 +12:00
```
mix igniter.new app_name --install ash --with phx.new --no-ecto
2024-06-13 12:41:07 +12:00
```
2024-06-06 02:12:07 +12:00
## Patterns
Mix tasks built with igniter are both individually callable, _and_ composable. This means that tasks can call eachother, and also end users can create and customize their own generators composing existing tasks.
### Installers
Igniter will look for a task called `<your_package>.install` when the user runs `mix igniter.install <your_package>`, and will run it after installing and fetching dependencies.
### Generators/Patchers
These can be run like any other mix task, or composed together. For example, lets say that you wanted to have your own `Ash.Resource` generator, that starts with the default `mix ash.gen.resource` task, but then adds or modifies files:
```elixir
# in lib/mix/tasks/my_app.gen.resource.ex
defmodule Mix.Tasks.MyApp.Gen.Resource do
use Igniter.Mix.Task
def igniter(igniter, [resource | _] = argv) do
2024-06-13 10:22:08 +12:00
resource = Igniter.Code.Module.parse(resource)
2024-06-06 02:12:07 +12:00
my_special_thing = Module.concat([resource, SpecialThing])
2024-06-13 10:22:08 +12:00
location = Igniter.Code.Module.proper_location(my_special_thing)
2024-06-06 02:12:07 +12:00
igniter
|> Igniter.compose_task("ash.gen.resource", argv)
|> Igniter.create_new_elixir_file(location, """
defmodule #{inspect(my_special_thing)} do
# this is the special thing for #{inspect()}
end
""")
end
end
```