--[=[
	@param parent Instance
	@return RBXScriptConnection

	Scans all descendants of `parent` and loads any ModuleScripts found, then
	calls `Component.new` on those loaded modules.

	Each component module class must have a `Tag` string property to map it
	to the proper tag.
]=]

function Component.Auto(parent)
	local function Setup(moduleScript)
		local m = require(moduleScript)
		assert(type(m) == "table", "Expected table for component")
		assert(type(m.Tag) == "string", "Expected .Tag property")
		Component.new(m.Tag, m, m.RenderPriority, m.RequiredComponents)
	end
	for _,v in ipairs(parent:GetDescendants()) do
		if v:IsA("ModuleScript") then
			Setup(v)
		end
	end
	return parent.DescendantAdded:Connect(function(v)
		if v:IsA("ModuleScript") then
			Setup(v)
		end
	end)
end

