shahryarjb
Create and replace mix.exs file
Hi my friends, Imaging you have a mix file which you want to change part of it and replace after doing your changes.
For example
defmodule Dvote.MixProject do
use Mix.Project
def project do
[ .. ]
end
def application do
[..... ]
end
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp deps do
[
{:phoenix, "~> 1.6.6"},
{:mishka_installer, git: "https://github.com/mishka-group/mishka_installer.git"}
]
end
defp aliases do
[.... ]
end
end
Now I just want to change deps function and keep the other same as the orginal file and create a new mix.exs file.
defp deps do
[
{:phoenix, "~> 1.6.6"},
{:mishka_installer, git: "https://github.com/mishka-group/mishka_installer.git"},
{:new_plug, "~> 1.0.0"}
]
end
So I need suggestions how to do this! Regex? Or the other way, you can offer me?!
After creating this file in runtime!! So we need to compile whole the project because it is exs file? Or we can hot reload with a way?!
Why I need something like this?
I let my user add a dep from hex site in runtime, but I need to change the mix file auto with code and do not make user get involved to changing this file manually
By the way, I load my new deps from a json file
Thank you
The simple code for this: https://github.com/mishka-group/mishka_installer/blob/master/lib/installer/run_time_sourcing.ex
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 7 of 7 Posts
cmo
You’re completely mad
shahryarjb
Thank you, I think it is going to help me to edit
deps, and it is a good target to learn more about macro.Why am I mad :)) ?
I will test it very soon.
lud
Remember that your
mix.exsfile is code. That means that thedepsfunction can return anything from anywhere, including using anything that is present in the erlang distribution likexmerlto read XML files for instance.You could then define the dependencies in an xml file, which could allow more control of the data.
So you want to provide an app that can be added new dependencies to, at runtime? What is is exactly that you are trying to do? If the code added that way is not needed for the project to run then it is not an actual dependency ; maybe you need to implement a plugin solution for instance?
shahryarjb
Hi dear @lud, I talked about this way I want to do in these post, I am open to receive any suggestion
and
and
in this video, you can see a simple demo
with these line I add a dep or delete it from my source
https://github.com/mishka-group/mishka_installer/blob/master/lib/installer/run_time_sourcing.ex#L10-L30
So, my user need to add his package into
depsfunction and I create this for him/herhttps://github.com/mishka-group/mishka_installer/blob/master/lib/installer/dep_handler.ex#L116-L127
So all the plugins are called from a JSON file which is created from my database
for example
So the only problem exist here that is keeping state when a dep was installed before. So my library let users register an event; before compiling I send a name of app and some information, if an app needs to save something, it prevents to
force_update, if not it is going to be run the bottom function.In this function, when the lib gets an answer, it sends a
pubsuto used admin dashboardhttps://github.com/mishka-group/mishka_installer/blob/master/lib/installer/dep_changes_protector.ex#L83-L97
A simple dashboard I’m developing it: https://github.com/mishka-group/mishka_installer/blob/master/lib/installer/live/dep_getter.ex after that I add it in my CMS: GitHub - shahryarjb/mishka-cms: MishkaCms an open source and real time API base CMS Powered by Elixir and Phoenix · GitHub
My solution for event
https://github.com/mishka-group/mishka_installer
lud
Ok so it looks like it is working, based on your demo.
I would still add special code to
mix.exsto fetch deps from another file instead of modifyingmix.exsitself. It can be an XML or it can be a binary file generater with:erlang.term_to_binary(new_deps).If you absolutely need to generate a new file then you can just change the path of the xml (or whatever format) in the mix.exs source. With the following code:
…a regex to update
@xml_path "path/to/file.xml"is easy.shahryarjb
There is a problem, I did not test with
xml, but with JSON, I can not call the function out of themixfile to convert JSON to list of tuples. Especially if you want to use a library, inexsfile under a mix project like:Mix.install([{:sourceror, github: "doorgan/sourceror"}]). And I call some essential information from my Genserver (on state), and mix file can not access to it.Please see this lines of code:
https://github.com/mishka-group/mishka_installer/blob/master/lib/installer/dep_handler.ex#L116-L127
mayel
You may be interested in reading the code we use for something similar: GitHub - bonfire-networks/mess: Simple, file-based dependency management with git and local overrides. · GitHub