View Source MishkaInstaller.Installer.DepHandler (Mishka Installer v0.0.4-beta.4)
A module aggregates several operational functions to simplify the integration of all activities,
including adding - removing, and updating a library in the project.
For this purpose, you can use this module directly in your program or just call some helper functions.
It should be noted that this module, like the MishkaInstaller.Installer.RunTimeSourcing
module,
has a primary function that performs all the mentioned operations based on the request type (run/2
).
Also, to perform some activities before applying any changes, the database and extensions.json
file of your project will be rechecked.
for-example-these-are-output-from-json-file-and-this-module-struct
For example, these are output from Json
file and this module struct
[
%{
app: :mishka_installer,
version: "0.0.2",
type: :git, # :hex, if user upload elixir libraries (path), we should keep them in a temporary folder, and Docker should make it valume
url: "https://github.com/mishka-group/mishka_installer", # if it is hex: https://hex.pm/packages/mishka_installer
git_tag: "0.0.2", # we consider it when it is a git, and if does not exist we get master,
custom_command: "ecto.migrate", # you can write nil or you task file like ecto.migrate
dependency_type: :none, # :force_update, When you use this, the RunTime sourcing check what dependencies you use
# in your program have a higher version compared to the old source. it just notice admin there is a update,
# it does not force the source to be updated.
dependencies: [ # this part let mishka_installer to know can update or not dependencies of a app, we should consider a backup file
%{app: :mishka_developer_tools, max: "0.0.2", min: "0.0.1"},
%{app: :mishka_social, max: "0.0.2", min: "0.0.1"}
]
}
]
OR
%MishkaInstaller.Installer.DepHandler{
app: "mishka_social",
version: "0.0.2 ",
type: "hex",
url: "https://hex.pm/packages/mishka_social",
git_tag: nil,
custom_command: nil,
dependency_type: "force_update",
dependencies: [
%{app: :phoenix, min: "1.6"},
%{app: :phoenix_live_view, max: "0.17.7", min: "0.17.7"},
%{app: :ueberauth, max: "0.17.7", min: "0.17.7"},
%{app: :ueberauth_github, min: "0.8.1"},
%{app: :ueberauth_google, min: "0.10.1"},
]
}
below-you-can-see-the-graph-of-connecting-this-module-to-another-module
Below you can see the graph of connecting this module to another module.
+----------------------------+ +-------------------------------------+
| | | |
| MishkaInstaller.Dependency | | MishkaInstaller.Installer.MixCreator|
| <---+ +----> |
+----------------------------+ | | +-------------------------------------+
| |
| | +-----------------------------------------+
| | | |
| | |MishkaInstaller.Installer.RunTimeSourcing|
| | | |
| | +---^-------------------------------------+
| | |
+--------------------------------+-+---+ |
| | |
| MishkaInstaller.Installer.DepHandler +----+
| |
+----------------------------^---------+
|
|
+------------------------+---------------+
| |
|MishkaInstaller.Installer.Live.DepGetter|
| |
+----------------------------------------+
Link to this section Summary
Types
This type can be used when you want to introduce an app to install
This is delegate of Application.loaded_applications/0
output
This type can be used when you want to introduce method of install a dependency
This type can be used when you want to put your data in this module struct
Functions
This function helps developers to decide what they should do when an app is going to be updated.
For example, each of the extensions maybe has states or necessary jobs; hence they can register their app for on_change_dependency
event.
This function mixes your current list of dependencies with your added-dependencies from extensions.json
.
With this function, you can check and create extensions.json
and its path.
A function to compare dependencies between extensions.json
and Application.loaded_applications/0
; if an app exists, it returns.
This function compare installed app based on their files in _build
and deps
directory.
This function works like compare_dependencies_with_json/0
, but there is a difference which is in this part of the code,
we compare the installed app with sup-dependencies based on min and max versions that are allowed.
This function helps you to compare an app version with its installed version, it returns true
or false
.
Based on Application.spec/2
This function creates extensions.json
as a json file.
For more information, please read create_mix_file_and_start_compile/2
, but consider this function just
re-creates mix.exs
file and does not compile an app. This function is based on the Sourceror
library.
This function provides an option to edit and start compiling from a mix.exs
file.
It should be considered to use this facility as a helper because it might be deleted on the next version from our primary process;
create_mix_file_and_start_compile/2
is kept to let developers use this based on their problems.
You must put two entries, the first one is the app name, and the second one is the type of compiling, which can be shown in a terminal
as stream outputs or sent with Pubsub
and Port
.
This function is based on the Sourceror
library, and the types we discussed include :cmd
and :port
.
This functions returns extensions.json
file path based on :project_path
.
It returns dependencies as a list of maps from mix.exs
It returns dependencies as a list of maps from mix.lock
, based on Mix.Dep.Lock.read
This function uses read_dep_json/0
to read extensions.json
file and returns list of dependencies-map.
With this function help you can move built app file to _build
folder.
This Function is for interacting with the external extensions.json
file to load added-libraries.
The run/2
function is actually the function of the installer and assembler of all the modules that this module is connected to.
This function has two inputs that you can see in the examples below. The first input is an atom, which specifies how to install a
library in the system.
Depending on the installation method, the second entry can be the dependency information requested for the installation.
Link to this section Types
This type can be used when you want to introduce an app to install
This is delegate of Application.loaded_applications/0
output
@type run() :: :hex | :git | :upload
This type can be used when you want to introduce method of install a dependency
@type t() :: %MishkaInstaller.Installer.DepHandler{ app: String.t() | nil, custom_command: String.t() | nil, dependencies: [map()], dependency_type: String.t() | nil, git_tag: String.t() | nil, type: String.t() | nil, url: String.t() | nil, version: String.t() | nil }
This type can be used when you want to put your data in this module struct
Link to this section Functions
@spec add_new_app(t()) :: {:ok, :add_new_app, any()} | {:error, :add_new_app, :changeset | :file, any()}
This function helps developers to decide what they should do when an app is going to be updated.
For example, each of the extensions maybe has states or necessary jobs; hence they can register their app for on_change_dependency
event.
examples
Examples
old_ueberauth = %DepHandler{
app: "ueberauth",
version: "0.6.3",
type: "hex",
url: "https://hex.pm/packages/ueberauth",
git_tag: nil,
custom_command: nil,
dependency_type: "force_update",
dependencies: [
%{app: :plug, min: "1.5.0"}
]
}
MishkaInstaller.Installer.DepHandler.add_new_app(old_ueberauth)
This function mixes your current list of dependencies with your added-dependencies from extensions.json
.
this-function-calls-1-other-function-including
This function calls 1 other function including:
examples
Examples
list_of_deps =
[
{:finch, "~> 0.12.0"},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:ueberauth, git: "url", tag: "0.6.3"}
]
MishkaInstaller.Installer.DepHandler.append_mix(list_of_deps)
check_or_create_deps_json(project_path \\ MishkaInstaller.get_config(:project_path))
View Source@spec check_or_create_deps_json(binary()) :: {:ok, :check_or_create_deps_json, String.t()} | {:error, :check_or_create_deps_json, String.t()}
With this function, you can check and create extensions.json
and its path.
examples
Examples
MishkaInstaller.Installer.DepHandler.check_or_create_deps_json()
compare_dependencies_with_json(installed_apps \\ Application.loaded_applications())
View Source@spec compare_dependencies_with_json(installed_apps() | any()) :: list() | {:error, :compare_dependencies_with_json, String.t()}
A function to compare dependencies between extensions.json
and Application.loaded_applications/0
; if an app exists, it returns.
this-function-calls-3-other-functions-including
This function calls 3 other functions including:
examples
Examples
MishkaInstaller.Installer.DepHandler.compare_dependencies_with_json()
@spec compare_installed_deps_with_app_file(String.t()) :: {:error, :compare_installed_deps_with_app_file, String.t()} | {:ok, :compare_installed_deps_with_app_file, list()}
This function compare installed app based on their files in _build
and deps
directory.
this-function-calls-4-other-functions-including
This function calls 4 other functions including:
MishkaInstaller.Installer.RunTimeSourcing.read_app/2
MishkaInstaller.Installer.RunTimeSourcing.consult_app_file/1
compare_version_with_installed_app/2
File.dir?/1
examples
Examples
MishkaInstaller.Installer.DepHandler.compare_installed_deps_with_app_file("app_name")
compare_sub_dependencies_with_json(installed_apps \\ Application.loaded_applications())
View Source@spec compare_sub_dependencies_with_json(any()) :: list() | {:error, :compare_sub_dependencies_with_json, String.t()}
This function works like compare_dependencies_with_json/0
, but there is a difference which is in this part of the code,
we compare the installed app with sup-dependencies based on min and max versions that are allowed.
examples
Examples
MishkaInstaller.Installer.DepHandler.compare_sub_dependencies_with_json()
reference
Reference
- How to improve sort of maps in a list which have duplicate key (https://elixirforum.com/t/47486)
This function helps you to compare an app version with its installed version, it returns true
or false
.
Based on Application.spec/2
examples
Examples
MishkaInstaller.Installer.DepHandler.compare_version_with_installed_app(app, version)
@spec create_deps_json_file(binary()) :: {:error, :check_or_create_deps_json, binary()} | {:ok, :check_or_create_deps_json, binary()}
This function creates extensions.json
as a json file.
examples
Examples
MishkaInstaller.Installer.DepHandler.create_deps_json_file(project_path)
@spec create_mix_file() :: :ok
For more information, please read create_mix_file_and_start_compile/2
, but consider this function just
re-creates mix.exs
file and does not compile an app. This function is based on the Sourceror
library.
examples
Examples
MishkaInstaller.Installer.DepHandler.create_mix_file()
This function provides an option to edit and start compiling from a mix.exs
file.
It should be considered to use this facility as a helper because it might be deleted on the next version from our primary process;
create_mix_file_and_start_compile/2
is kept to let developers use this based on their problems.
You must put two entries, the first one is the app name, and the second one is the type of compiling, which can be shown in a terminal
as stream outputs or sent with Pubsub
and Port
.
This function is based on the Sourceror
library, and the types we discussed include :cmd
and :port
.
this-function-calls-3-other-functions-including
This function calls 3 other functions including:
create_deps_json_file/1
MishkaInstaller.Installer.MixCreator.backup_mix/1
MishkaInstaller.Installer.DepChangesProtector.deps/2
examples
Examples
MishkaInstaller.Installer.DepHandler.create_mix_file_and_start_compile(app, type)
@spec extensions_json_path() :: binary()
This functions returns extensions.json
file path based on :project_path
.
examples
Examples
MishkaInstaller.Installer.DepHandler.extensions_json_path()
It returns dependencies as a list of maps from mix.exs
examples
Examples
MishkaInstaller.Installer.DepHandler.get_deps_from_mix(MishkaInstaller.MixProject)
@spec get_deps_from_mix_lock() :: list()
It returns dependencies as a list of maps from mix.lock
, based on Mix.Dep.Lock.read
examples
Examples
MishkaInstaller.Installer.DepHandler.get_deps_from_mix_lock()
@spec mix_read_from_json() :: list()
This function uses read_dep_json/0
to read extensions.json
file and returns list of dependencies-map.
examples
Examples
MishkaInstaller.Installer.DepHandler.mix_read_from_json()
With this function help you can move built app file to _build
folder.
this-function-calls-3-other-functions-including
This function calls 3 other functions including:
MishkaInstaller.Installer.RunTimeSourcing.do_runtime/2
MishkaInstaller.Installer.RunTimeSourcing.get_build_path/0
File.cp_r/3
examples
Examples
MishkaInstaller.Installer.DepHandler.move_and_replace_compiled_app_build(app_list)
This Function is for interacting with the external extensions.json
file to load added-libraries.
examples
Examples
MishkaInstaller.Installer.DepHandler.read_dep_json()
# or
MishkaInstaller.Installer.DepHandler.mix_read_from_json(JSON_PATH)
The run/2
function is actually the function of the installer and assembler of all the modules that this module is connected to.
This function has two inputs that you can see in the examples below. The first input is an atom, which specifies how to install a
library in the system.
Depending on the installation method, the second entry can be the dependency information requested for the installation.
examples
Examples
Application.spec(:timex, :vsn)
MishkaInstaller.Installer.DepHandler.run(:hex, "faker")
app = %{url: "https://github.com/bitwalker/timex", tag: "3.7.5"}
MishkaInstaller.Installer.DepHandler.run(:git, app)
app = %{url: "https://github.com/bitwalker/timex", tag: "3.7.6"}
MishkaInstaller.Installer.DepHandler.run(:git, app)
app = %{url: "https://github.com/bitwalker/timex", tag: "3.7.8"}
MishkaInstaller.Installer.DepHandler.run(:git, app)
app = %{url: "https://github.com/elixirs/faker", tag: "v0.17.0"}
MishkaInstaller.Installer.DepHandler.run(:git, app)
app = %{url: "https://github.com/martinsvalin/html_entities", tag: "v0.5.1"}
MishkaInstaller.Installer.DepHandler.run(:git, app)
app = %{url: "https://github.com/beatrichartz/csv", tag: "v2.3.0"}
MishkaInstaller.Installer.DepHandler.run(:git, app)
MishkaInstaller.Installer.DepHandler.run(:upload, ["../mishka_installer/deployment/extensions/timex-3.7.8.zip"])
reference
Reference
- Fix phoenix reload issue when a dependency is compiled (https://github.com/phoenixframework/phoenix/issues/4278)
Phoenix.CodeReloader.reload/1
(https://hexdocs.pm/phoenix/Phoenix.CodeReloader.html#reload/1)