diff --git a/src/awesomewm.d.tl/init.tl b/src/awesomewm.d.tl/init.tl index bfca4ca..c28b4cc 100644 --- a/src/awesomewm.d.tl/init.tl +++ b/src/awesomewm.d.tl/init.tl @@ -11,32 +11,64 @@ local log = logger.log("main") log:info(logger.message_with_metadata("Start", { property = property })) -local index = crawler.fetch(property.base_url .. property.index_uri) +local function module_lists( + doc_index_url: string, + global_modules: List, + ignored_modules: List +): List, List, List + local index = crawler.fetch(doc_index_url) + local all_module_infos = List(scraper.module_info_list.get_modules_from_index(index)) -local ignored_modules = List(property.ignored_modules) -local module_infos = List(scraper.module_info_list.get_modules_from_index(index)):filter( - function(module: Module_Info.Module_Info): boolean - return not ignored_modules:contains(module.name) + local global_module_infos: List = List() + local module_infos: List = List() + + for module in all_module_infos:iter() do + if global_modules:contains(module.name) then + global_module_infos:append(module) + elseif not ignored_modules:contains(module.name) then + module_infos:append(module) + end end + + return all_module_infos, module_infos, global_module_infos +end + +local function do_one_file( + url: string, + record_name: string, + output_path: string ) - -log:info("Finished Module List scrapping, found " .. #module_infos .. " modules") - -local function do_one_file(url: string, output_base_dir: string) - local module_name = url:gsub(".*/", ""):gsub(".html", "") local html = crawler.fetch(url) - local module_doc = scraper.module_doc.get_doc_from_page(html, module_name) + local module_doc = scraper.module_doc.get_doc_from_page(html, record_name) module_doc:fixup() module_doc:populate_requires() filesystem.file_writer.write( generator.teal_type_definitions.generate_teal(module_doc), - output_base_dir .. module_name:gsub("%.", "/") .. ".d.tl" + output_path ) end -for i = 1, #module_infos do +local all_module_infos, module_infos, global_module_infos = module_lists( + property.base_url .. property.index_uri, + List(property.capi_modules), + List(property.ignored_modules) +) + +log:info( + logger.message_with_metadata( + "Finished Module List scrapping", + { + total_module_count = #all_module_infos, + module_count = #module_infos, + global_module_count = #global_module_infos + } + ) +) + +for module in module_infos:iter() do do_one_file( - property.base_url .. "/" .. module_infos[i].uri, - property.out_directory .. "/" + property.base_url .. "/" .. module.uri, + module.name, + property.out_directory .. "/" .. module.name:gsub("%.", "/") .. ".d.tl" ) end