Files
metabuilder/packages/package_validator/seed/scripts/validate_scripts_structure.lua
JohnDoe6345789 73fb98d053 feat: Enhance package validator with comprehensive Lua validation scripts
- Added validation scripts for Lua quality, syntax, structure, and naming conventions.
- Implemented checks for metadata and component structures, ensuring compliance with defined schemas.
- Introduced validation for test file structures and common test files when lua_test is a devDependency.
- Updated manifest to include new Lua scripts for sorting, filtering, selection, and export functionalities.
- Improved documentation in UI_TO_LUA_MIGRATION.md to reflect current progress and completed phases.
2025-12-30 11:13:41 +00:00

59 lines
1.8 KiB
Lua

--- Validates scripts directory structure
---@param package_path string Path to the package
---@param metadata Metadata Package metadata
---@return string[] errors List of errors
---@return string[] warnings List of warnings
local function validate_scripts_structure(package_path, metadata)
local errors = {}
local warnings = {}
local scripts_path = package_path .. "/scripts"
-- Check if scripts directory exists when exports.scripts is defined
if metadata.exports and metadata.exports.scripts and #metadata.exports.scripts > 0 then
local dir_exists = false
local test_file = io.open(scripts_path .. "/init.lua", "r")
if test_file then
test_file:close()
dir_exists = true
end
if not dir_exists then
table.insert(errors, "scripts/ directory required when exports.scripts is defined")
end
-- Check for init.lua
local init_file = io.open(scripts_path .. "/init.lua", "r")
if not init_file then
table.insert(warnings, "scripts/init.lua is recommended as entry point")
else
init_file:close()
end
-- Check for tests directory if lua_test is a devDependency
local has_lua_test = false
if metadata.devDependencies then
for _, dep in ipairs(metadata.devDependencies) do
if dep == "lua_test" then
has_lua_test = true
break
end
end
end
if has_lua_test then
-- lua_test is a devDependency, so tests are expected
local test_init = io.open(scripts_path .. "/tests/metadata.test.lua", "r")
if not test_init then
table.insert(warnings, "scripts/tests/ directory with test files recommended when lua_test is a devDependency")
else
test_init:close()
end
end
end
return errors, warnings
end
return validate_scripts_structure