-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
262 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
return { | ||
env_variable = "NVIM_LARAVEL_ENV", | ||
auto_dicover = true, | ||
default = "local", | ||
definitions = { | ||
["sail"] = { | ||
condition = { | ||
file_exists = { "vendor/bin/sail", "docker-compose.yml" }, | ||
}, | ||
commands = { | ||
sail = { "vendor/bin/sail" }, | ||
{ | ||
commands = { "php", "composer", "npm", "yarn" }, | ||
prefix = { "vendor/bin/sail" }, | ||
}, | ||
}, | ||
}, | ||
["docker-compose"] = { | ||
condition = { | ||
file_exists = { "docker-compose.yml" }, | ||
executable = { "docker" }, | ||
}, | ||
commands = { | ||
compose = { "docker", "compose" }, | ||
{ | ||
commands = { "php", "composer", "npm" }, | ||
docker = { | ||
container = { | ||
env = "APP_SERVICE", | ||
default = "app", | ||
}, | ||
exec = { "docker", "compose", "exec", "-it" }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
["local"] = { | ||
condition = { | ||
executable = { "php" }, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
local get_env = require("laravel.utils").get_env | ||
|
||
---@class Environment | ||
---@field name string | ||
---@field condition table|nil | ||
---@field commands table | ||
local Environment = {} | ||
|
||
local cache = {} | ||
|
||
---@param env table | ||
---@return Environment | ||
function Environment:new(name, env) | ||
local obj = { | ||
name = name, | ||
condition = env.condition or nil, | ||
commands = env.commands or {}, | ||
} | ||
|
||
setmetatable(obj, self) | ||
self.__index = self | ||
|
||
return obj | ||
end | ||
|
||
---@return boolean | ||
function Environment:check() | ||
if not self.condition then | ||
return true | ||
end | ||
|
||
for _, file in pairs(self.condition.file_exists or {}) do | ||
if vim.fn.filereadable(file) ~= 1 then | ||
return false | ||
end | ||
end | ||
|
||
for _, exec in pairs(self.condition.executable or {}) do | ||
if vim.fn.executable(exec) == 0 then | ||
return false | ||
end | ||
end | ||
|
||
return true | ||
end | ||
|
||
---@param name string | ||
---@return table|nil | ||
function Environment:executable(name) | ||
if cache[name] then | ||
return cache[name] | ||
end | ||
|
||
-- check commands directly by name | ||
if self.commands[name] then | ||
cache[name] = self.commands[name] | ||
return cache[name] | ||
end | ||
|
||
for _, value in pairs(self.commands) do | ||
if vim.tbl_contains(value.commands or {}, name) then | ||
-- is on the list have to process it | ||
if value.docker then | ||
-- is set to run from docker | ||
if not value.docker.container then | ||
error( | ||
"Configuration indicates docker but there is no container information, check the configuration", | ||
vim.log.levels.ERROR | ||
) | ||
end | ||
|
||
local container = value.docker.container.default | ||
if value.docker.container.env and get_env(value.docker.container.env) then | ||
container = get_env(value.docker.container.env) | ||
end | ||
|
||
if not container then | ||
error("Could not resolve container name check the configuration", vim.log.levels.ERROR) | ||
end | ||
|
||
if not value.docker.exec then | ||
error("Need to define a docker exec command", vim.log.levels.ERROR) | ||
end | ||
|
||
cache[name] = vim.fn.extend(value.docker.exec, { container, name }) | ||
|
||
return cache[name] | ||
end | ||
|
||
if value.prefix then | ||
cache[name] = vim.fn.extend(value.prefix, { name }) | ||
|
||
return cache[name] | ||
end | ||
end | ||
end | ||
|
||
-- if is not define look for the executable in the system | ||
if vim.fn.executable(name) == 1 then | ||
cache[name] = { name } | ||
return { name } | ||
end | ||
|
||
return nil | ||
end | ||
|
||
return Environment |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.