+17
-24
@@ -31,21 +31,7 @@ local fileproc = {} :: FileProc
|
||||
]]--
|
||||
function fileproc.collectFiles(opts: types.opts): {string}
|
||||
assert(typeof(opts) == "table", "Expected opts to be of type 'table'")
|
||||
local filesWithWorkspace = {}
|
||||
|
||||
local function processDir(dirPath)
|
||||
for _, file in pairs(fs.readDir(dirPath)) do
|
||||
local fullPath = dirPath .. "/" .. file
|
||||
if fs.isDir(fullPath) then
|
||||
processDir(fullPath)
|
||||
elseif fs.isFile(fullPath) then
|
||||
if opts.forceBinaryRead or core.isValidModelFile(file) then
|
||||
table.insert(filesWithWorkspace, fullPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local filesToProcess = opts.filesToProcess or {}
|
||||
if opts.directoryMode then
|
||||
if not opts.directoryPath or not fs.isDir(opts.directoryPath) then
|
||||
stdio.write(stdio.color("red"))
|
||||
@@ -53,28 +39,35 @@ function fileproc.collectFiles(opts: types.opts): {string}
|
||||
stdio.write(stdio.color("reset"))
|
||||
process.exit(1)
|
||||
end
|
||||
|
||||
processDir(opts.directoryPath)
|
||||
|
||||
if #filesWithWorkspace == 0 then
|
||||
local function readDirLoop(dirPath)
|
||||
for _, file in pairs(fs.readDir(dirPath)) do
|
||||
local fullPath = dirPath .. "/" .. file
|
||||
if fs.isFile(fullPath) then
|
||||
if opts.forceBinaryRead or core.isValidModelFile(file) then
|
||||
table.insert(filesToProcess, fullPath)
|
||||
end
|
||||
elseif fs.isDir(fullPath) then
|
||||
readDirLoop(fullPath)
|
||||
end
|
||||
end
|
||||
end
|
||||
readDirLoop(opts.directoryPath)
|
||||
if #filesToProcess == 0 then
|
||||
stdio.write(stdio.color("yellow"))
|
||||
stdio.write(`Warning: No files found in directory {opts.directoryPath}.\n`)
|
||||
stdio.write(stdio.color("reset"))
|
||||
process.exit(0)
|
||||
end
|
||||
end
|
||||
|
||||
if #filesWithWorkspace == 0 then
|
||||
if #filesToProcess == 0 then
|
||||
stdio.write(stdio.color("red"))
|
||||
stdio.write("Error: No files to process.\n")
|
||||
stdio.write(stdio.color("reset"))
|
||||
process.exit(1)
|
||||
end
|
||||
|
||||
return filesWithWorkspace
|
||||
return filesToProcess
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
Processes each file and checks for workspace instances.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user