Skip to content

Commit

Permalink
fixed internals.util.get_root_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Mar 8, 2021
1 parent 3775490 commit a8bcc2f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion config.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
version: 0.14.0
version: 0.14.1
global_modules: false//disables global modules loading (only looks up for modules in cwd)
minify: true
inject_CA: true
Expand Down
63 changes: 33 additions & 30 deletions lib/eli/internals/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,38 @@ local _separator = require "eli.path".default_sep()
local _join = require "eli.extensions.string".join

local function _get_root_dir(paths)
-- check whether we have all files in same dir
local _rootDirSegments = {}
for _, _path in ipairs(paths) do
if #_rootDirSegments == 0 then
for _segment in string.gmatch(_path, "(.-)" .. _separator) do
table.insert(_rootDirSegments, _segment)
end
else
local j = 1
for _segment in string.gmatch(_path, "(.-)" .. _separator) do
if _segment ~= _rootDirSegments[j] then
_rootDirSegments = table.move(_rootDirSegments, 1, j - 1, 1, {})
break
end
j = j + 1
end
end
-- check whether we have all files in same dir
local _rootDirSegments = {}
for _, _path in ipairs(paths) do
if #_rootDirSegments == 0 then
for _segment in string.gmatch(_path, "(.-)" .. _separator) do
table.insert(_rootDirSegments, _segment)
end
else
if not string.find(_path, "(.-)" .. _separator) then
return "" -- found file in root, no usable root dir
end
local j = 1
for _segment in string.gmatch(_path, "(.-)" .. _separator) do
if _segment ~= _rootDirSegments[j] then
_rootDirSegments = table.move(_rootDirSegments, 1, j - 1, 1, {})
break
end
j = j + 1
end
end

if #_rootDirSegments == 0 then
break
end
end
local _rootDir = _join("/", table.unpack(_rootDirSegments))
if type(_rootDir) == "string" and #_rootDir > 0 and _rootDir:sub(#_rootDir, #_rootDir) ~= _separator then
_rootDir = _rootDir .. _separator
end
return _rootDir or ""
end
if #_rootDirSegments == 0 then
break
end
end
local _rootDir = _join("/", table.unpack(_rootDirSegments))
if type(_rootDir) == "string" and #_rootDir > 0 and _rootDir:sub(#_rootDir, #_rootDir) ~= _separator then
_rootDir = _rootDir .. _separator
end
return _rootDir or ""
end

return {
get_root_dir = _get_root_dir
}
return {
get_root_dir = _get_root_dir
}

0 comments on commit a8bcc2f

Please sign in to comment.