Skip to content

Commit

Permalink
VIP - fix some type
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Jun 26, 2024
1 parent d67638d commit c367754
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/installer/installer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ defmodule MishkaInstaller.Installer.Installer do
# |__ TODO: Store builded files for re-start project
# |__ TODO: Update all stuff in mnesia db
# TODO: Add some broadcasting to know what is the state of installing
@spec install(t()) :: error_return() | okey_return()
def install(app) when app.type == :extracted do
with {:ok, data} <- __MODULE__.builder(app),
:ok <- mix_exist(data.path),
Expand All @@ -104,6 +105,7 @@ defmodule MishkaInstaller.Installer.Installer do
File.cd!(MishkaInstaller.__information__().path)
end

@spec uninstall(atom()) :: :ok
def uninstall(app) do
Application.stop(app.app)
Application.unload(app.app)
Expand All @@ -112,6 +114,7 @@ defmodule MishkaInstaller.Installer.Installer do
:ok
end

@spec uninstall(atom(), Path.t()) :: :ok
def uninstall(app, custom_path) do
Application.stop(app)
Application.unload(app)
Expand Down
12 changes: 9 additions & 3 deletions lib/installer/library_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ defmodule MishkaInstaller.Installer.LibraryHandler do

@type error_return :: {:error, [%{action: atom(), field: atom(), message: String.t()}]}

@type okey_return :: {:ok, struct() | map() | binary()}
@type okey_return :: {:ok, struct() | map() | binary() | list(any())}

@type app :: Installer.t()
@type app :: Installer.t() | map()

@type runtime_type :: :add | :force_update | :uninstall

Expand All @@ -38,6 +38,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
####################################################################################
######################### (▰˘◡˘▰) Functions (▰˘◡˘▰) ##########################
####################################################################################
@spec prepend_compiled_apps(list(tuple())) :: :ok | error_return()
def prepend_compiled_apps(files_list) do
prepend =
Enum.reduce(files_list, [], fn {app_name, path}, acc ->
Expand Down Expand Up @@ -146,6 +147,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
# 1. delete and unload old app
# 2. move new app
# 3. return list of moved apps
@spec move_and_replace_build_files(Installer.t()) :: okey_return() | error_return()
def move_and_replace_build_files(app) do
path = extensions_path()
info = MishkaInstaller.__information__()
Expand All @@ -164,7 +166,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
end
end)

if length(moved_files) > 0 do
if moved_files != [] do
{:ok, moved_files}
else
message = "There is no app to be replicated in the requested path."
Expand Down Expand Up @@ -234,6 +236,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
end
end

@spec consult_app_file(Path.t()) :: {:ok, term()} | {:error, any()}
def consult_app_file(bin) do
# The path could be located in an .ez archive, so we use the prim loader.
with {:ok, tokens, _} <- :erl_scan.string(String.to_charlist(bin)) do
Expand Down Expand Up @@ -272,6 +275,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
end
end

@spec application_ensure(atom()) :: :ok | error_return()
def application_ensure(app_name) do
with {:load, :ok} <- {:load, Application.load(app_name)},
{:all, {:ok, _apps}} <- {:all, Application.ensure_all_started(app_name)} do
Expand All @@ -289,6 +293,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
end
end

@spec unload(atom()) :: :ok | error_return()
def unload(app) do
case Application.unload(app) do
{:error, {:not_loaded, ^app}} ->
Expand Down Expand Up @@ -356,6 +361,7 @@ defmodule MishkaInstaller.Installer.LibraryHandler do
end
end

@spec extensions_path() :: Path.t()
def extensions_path() do
info = MishkaInstaller.__information__()
Path.join(info.path, ["deployment/", "#{info.env}/", "extensions"])
Expand Down

0 comments on commit c367754

Please sign in to comment.