dkuku

dkuku

I’m trying to run a task before the app is compiled so I can patch the source of dependency.
mix deps.get runs this way and I can’t figure out how to do this?

Showing Posts 1 to 5

hst337

hst337

Is this a task from dependency or is it a part of a project?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

If you need to change the source code of a dependency, I would copy the source code to another directory or git repo that you manage, edit the source code there, and then point the mix.exs deps entry to that new source location.

I think trying to edit it in the deps directory directly with a mix task is going to be swimming upstream from how it’s designed to be used.

dkuku

dkuku OP

I was editing the task it my current app directory. As I understand it is enough to create a lib from it and I it with escript or archive install (like phoenix installer)

mayel

mayel

I like to make my mix tasks double up as escripts for this purpose:

# lib/mix/tasks/secrets/mix.exs
defmodule Bonfire.Secrets do
  use Mix.Project

  def project do
    [
      app: :secrets,
      version: "0.1.0-alpha.1",
      elixir: "~> 1.11",
      escript: [main_module: Mix.Tasks.Bonfire.Secrets]
    ]
  end
end

# lib/mix/tasks/secrets/lib/secrets.ex
defmodule Mix.Tasks.Bonfire.Secrets do
  @shortdoc "Generates some secrets"

  @moduledoc """
  Generates random secrets and prints to the terminal.
  > mix bonfire.secrets [length]

  Can also compile/run it as an escript (without having to first compile the app):
  > cd lib/mix/tasks/secrets && mix escript.build && ./secrets [length]
  """
  use Mix.Task

  # for running as escript
  def main(args) do
    run(args)
  end

  @doc false
  def run([]), do: run(["64"])

  def run([int]),
    do: int |> parse!() |> random_string() |> Kernel.<>("\r\n") |> IO.puts()

  def run([int, iterate]), do: for(_ <- 1..parse!(iterate), do: run([int]))
  def run(args), do: nil

  defp parse!(int) do
    case Integer.parse(int) do
      {int, ""} -> int
      _ -> 64
    end
  end

  defp random_string(length) when length > 31 do
    :crypto.strong_rand_bytes(length)
    |> Base.encode64()
    |> binary_part(0, length)
  end
end
dkuku

dkuku OP

thanks, It’s useful

— All posts loaded —

Where Next? Top

Trending in Discussions Top

cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
515 12931 101
New
wmnnd
Hey folks, I wanted to share with you a project I’ve been working on for a while: It’s an Open Source (AGPLv3) newsletter tool. Think Ma...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
Ganna
Hi everyone, I have 8 years of production experience with Erlang/OTP and I’m just starting to get to know Elixir. What would you learn f...
New
gtcode
I’ve been tinkering with Lynx (by José) via hold_ledger. I used AI to write the code, a separate specification, the tests, and the Lean p...
New
AstonJ
A remark @Garrison made… ..has already inspired a thread for the technical side of reclaiming our internet, but there is of course anot...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews