alfredfriedrich

alfredfriedrich

Hello again fine folks of the elixir community,

I am struggling to write a small mix install task with Igniter. Basically I want to create some files in the install task, but if I create a new mix project with igniter.new foo --install my_app no matter what I try, my task does not seem to get called.

I a nutshell this is what I am trying to do:

$ mix igniter.new my_app
$ cd my_app
$ mix igniter.gen.task my_app.install

Inside the my_app.install.ex file I changed the igniter(igniter) function to look like this:

@impl Igniter.Mix.Task
def igniter(igniter) do
  # Do your work here and return an updated igniter
  igniter
  |> Igniter.create_new_file(Path.expand("lib/foo.ex"), foo_ex())
  |> Igniter.add_notice("mix my_app.install finished.")
end

defp foo_ex() do
  """
  defmodule MyApp.Foo do
  end
  """
end

When I try to run the installer in a new mix project (with igniter.new --install or with igniter.new + igniter.install afterwards) I always get the message No proposed content changes! :

mix igniter.new dummy --install my_app@path:../../my_app --verbose
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/dummy.ex
* creating test
* creating test/test_helper.exs
* creating test/dummy_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd dummy
    mix test

Run "mix help" for more commands.
Fetching and compiling dependencies ✔
Updating project's igniter dependency:
Updating project's igniter dependency: ✔
installing igniter:
installing igniter: ✔
compiling igniter:
===> Analyzing applications...
===> Compiling telemetry
compiling igniter: ✔
setting up igniter:
setting up igniter: ✔
compiling my_app ✔
`my_app.install` ✔

The following installer was found and executed: `my_app.install`:

    No proposed content changes!


Successfully installed:

* my_app

I also tried with a git URI instead of a local file URI for the dependency but same result.

When I call the mix my_app.install task directly from the my_app project I do get the desired output:

Igniter:

Create: lib/my_app/foo.ex

1 |defmodule MyApp.Foo do
2 |end
3 |

What do I miss? I am grateful for any pointers and hints.

Showing Posts 1 to 6

zachdaniel

zachdaniel

Creator of Ash

Make sure that your library has igniter as an optional dependency and see if that helps :slight_smile: you might need to blow away the build folder in any other project you’ve added this dep to to get it to pick up the dep change

alfredfriedrich

alfredfriedrich OP

Same behaviour with optional: true, with path: and with git: URI
As for the build directory, I use a small test script the make sure I get a clean state:

#!/bin/sh

if [ -d dummy ]; then
	echo "removing old dummy directory.."
	rm -rf dummy
fi

if [ "$1" = "git" ]; then
	mix igniter.new dummy --install my_app@git:http://my.git.server/my_app.git --verbose
else
	mix igniter.new dummy --install my_app@path:../../my_app --verbose
fi
zachdaniel

zachdaniel

Creator of Ash

Can I see specifically what the mix.exs look like of the package you’re trying to install?

alfredfriedrich

alfredfriedrich OP

Sure, it is a stock mix project with igniter:

defmodule MyApp.MixProject do
  use Mix.Project

  def project do
    [
      app: :my_app,
      version: "0.1.0",
      elixir: "~> 1.17",
      start_permanent: Mix.env() == :prod,
      consolidate_protocols: Mix.env() != :dev,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:igniter, "~> 0.5", only: [:dev, :test], optional: true}
      # {:dep_from_hexpm, "~> 0.3.0"},
      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
    ]
  end
end
zachdaniel

zachdaniel

Creator of Ash

You need to remove the only and have it just be optional: true :slight_smile:

alfredfriedrich

alfredfriedrich OP

That did the trick, thanks a lot Zach, much appreciate your help!

In hindsight, I should have read the :env part on the mix deps task documentation more thoroughly:

:env - the environment (as an atom) to run the dependency on; defaults to :prod. 
— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews