diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/glob/gitignore.lua | 7 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 67 |
2 files changed, 34 insertions, 40 deletions
diff --git a/script/glob/gitignore.lua b/script/glob/gitignore.lua index 4320e129..7dfd4591 100644 --- a/script/glob/gitignore.lua +++ b/script/glob/gitignore.lua @@ -116,6 +116,7 @@ function mt:checkDirectory(catch, path, matcher) end function mt:simpleMatch(path) + path = path:gsub('^[/\\]+', '') for i = #self.matcher, 1, -1 do local matcher = self.matcher[i] local catch = matcher(path) @@ -147,18 +148,18 @@ function mt:finishMatch(path) return false end -function mt:scan(callback) +function mt:scan(root, callback) local files = {} if type(callback) ~= 'function' then callback = nil end local list = {} - local result = self:callInterface('list', '') + local result = self:callInterface('list', root) if type(result) ~= 'table' then return files end for _, path in ipairs(result) do - list[#list+1] = path:match '([^/\\]+)[/\\]*$' + list[#list+1] = path end while #list > 0 do local current = list[#list] diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index fe709453..c493823d 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -34,34 +34,32 @@ function m.init(uri) log.init(ROOT, logPath) end -local function interfaceFactory(root) - return { - type = function (path) - local result - pcall(function () - if fs.is_directory(path) then - result = 'directory' - else - result = 'file' - end - end) - return result - end, - list = function (path) - local fullPath = fs.path(root .. '/' .. path) - if not fs.exists(fullPath) then - return nil +local globInteferFace = { + type = function (path) + local result + pcall(function () + if fs.is_directory(fs.path(path)) then + result = 'directory' + else + result = 'file' end - local paths = {} - pcall(function () - for fullpath in fullPath:list_directory() do - paths[#paths+1] = fullpath:string() - end - end) - return paths + end) + return result + end, + list = function (path) + local fullPath = fs.path(path) + if not fs.exists(fullPath) then + return nil end - } -end + local paths = {} + pcall(function () + for fullpath in fullPath:list_directory() do + paths[#paths+1] = fullpath:string() + end + end) + return paths + end +} --- 创建排除文件匹配器 function m.getNativeMatcher() @@ -72,7 +70,6 @@ function m.getNativeMatcher() return m.nativeMatcher end - local interface = interfaceFactory(m.path) local pattern = {} -- config.workspace.ignoreDir for path in pairs(config.config.workspace.ignoreDir) do @@ -123,7 +120,7 @@ function m.getNativeMatcher() pattern[#pattern+1] = path end - m.nativeMatcher = glob.gitignore(pattern, m.matchOption, interface) + m.nativeMatcher = glob.gitignore(pattern, m.matchOption, globInteferFace) m.nativeVersion = config.version return m.nativeMatcher @@ -146,7 +143,7 @@ function m.getLibraryMatchers() for path, pattern in pairs(librarys) do if fs.exists(fs.path(path)) then local nPath = fs.absolute(fs.path(path)):string() - local matcher = glob.gitignore(pattern, m.matchOption) + local matcher = glob.gitignore(pattern, m.matchOption, globInteferFace) if platform.OS == 'Windows' then matcher:setOption 'ignoreCase' end @@ -174,7 +171,7 @@ end local function loadFileFactory(root, progress, isLibrary) return function (path) - local uri = furi.encode(root .. '/' .. path) + local uri = furi.encode(path) if not files.isLua(uri) then return end @@ -252,15 +249,11 @@ function m.awaitPreload() local native = m.getNativeMatcher() local librarys = m.getLibraryMatchers() if native then - native:scan(nativeLoader) + native:scan(m.path, nativeLoader) end for _, library in ipairs(librarys) do - local libraryInterface = interfaceFactory(library.path) - local libraryLoader = loadFileFactory(library.path, progress, true) - for k, v in pairs(libraryInterface) do - library.matcher:setInterface(k, v) - end - library.matcher:scan(libraryLoader) + local libraryLoader = loadFileFactory(library.path, progress, true) + library.matcher:scan(library.path, libraryLoader) end log.info(('Found %d files.'):format(progress.max)) |