feat: implement `global_env_def`
This commit is contained in:
parent
b8cd7e3db8
commit
a2a063882a
|
@ -0,0 +1,55 @@
|
|||
local List = require "pl.List"
|
||||
local Module_Doc = require "entity.Module_Doc"
|
||||
local template = require "pl.template"
|
||||
local utils = require "utils"
|
||||
local snippets = require "generator.snippets"
|
||||
|
||||
-- The long therm goal is to have so many `snippets.render_*` functions that
|
||||
-- we can render the whole file with the smallest template possible.
|
||||
local tmpl = [[
|
||||
-- Auto generated file (Do not manually edit this file!)
|
||||
|
||||
# for module in modules:iter() do
|
||||
global record $(module.record_name)
|
||||
# if #module.signals ~= 0 then
|
||||
$(snippets.indent(snippets.render_enum("Signal", module.signals)))
|
||||
|
||||
# end -- /signals
|
||||
# if #module.methods ~= 0 then
|
||||
-- Object methods
|
||||
$(snippets.indent(snippets.render_record_functions(module.methods)))
|
||||
|
||||
# end -- /methods
|
||||
# if #module.properties ~= 0 then
|
||||
-- Object properties
|
||||
$(snippets.indent(snippets.render_record_properties(module.properties)))
|
||||
|
||||
# end -- /properties
|
||||
# if #module.constructors ~= 0 then
|
||||
-- Constructors
|
||||
$(snippets.indent(snippets.render_record_functions(module.constructors)))
|
||||
|
||||
# end -- /constructors
|
||||
# if #module.static_functions ~= 0 then
|
||||
-- Static functions
|
||||
$(snippets.indent(snippets.render_record_functions(module.static_functions)))
|
||||
# end -- /static_functions
|
||||
end
|
||||
|
||||
# end -- /modules
|
||||
]]
|
||||
|
||||
local module = {}
|
||||
|
||||
function module.generate_teal(data: List<Module_Doc.Module_Doc>): string
|
||||
local tmpl_args = {
|
||||
ipairs = ipairs,
|
||||
modules = data,
|
||||
snippets = snippets,
|
||||
}
|
||||
return utils.do_or_fail(template.substitute, tmpl, tmpl_args)
|
||||
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
return {
|
||||
global_env_def = require "generator.global_env_def",
|
||||
teal_type_definitions = require "generator.teal_type_definitions",
|
||||
snippets = require "generator.snippets",
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
local crawler = require "crawler"
|
||||
local filesystem = require "filesystem"
|
||||
local generator = require "generator"
|
||||
local List = require "pl.List"
|
||||
local logger = require "logger"
|
||||
local Module_Doc = require "entity.Module_Doc"
|
||||
local Module_Info = require "entity.Module_Info"
|
||||
local property = require "property"
|
||||
local scraper = require "scraper"
|
||||
local generator = require "generator"
|
||||
local utils = require "utils"
|
||||
|
||||
local log = logger.log("main")
|
||||
|
||||
|
@ -72,3 +74,24 @@ for module in module_infos:iter() do
|
|||
property.out_directory .. "/" .. module.name:gsub("%.", "/") .. ".d.tl"
|
||||
)
|
||||
end
|
||||
|
||||
local global_env_def: List<Module_Doc.Module_Doc> = List()
|
||||
for module in global_module_infos:iter() do
|
||||
if module.name:gmatch(".*%sand%s.*") then
|
||||
do_one_file(
|
||||
property.base_url .. "/" .. module.uri,
|
||||
module.name,
|
||||
property.out_directory .. "/" .. module.name:gsub(".*%sand%s", ""):gsub("%.", "/") .. ".d.tl"
|
||||
)
|
||||
end
|
||||
|
||||
local html = crawler.fetch(property.base_url .. "/" .. module.uri)
|
||||
local module_doc = scraper.module_doc.get_doc_from_page(html, (module.name:gsub("%sand%s.*", "")))
|
||||
module_doc:fixup()
|
||||
module_doc.record_name = utils.lowercase(module_doc.record_name)
|
||||
global_env_def:append(module_doc)
|
||||
end
|
||||
filesystem.file_writer.write(
|
||||
generator.global_env_def.generate_teal(global_env_def),
|
||||
property.out_directory .. "/global_env.d.tl"
|
||||
)
|
||||
|
|
|
@ -43,6 +43,10 @@ function utils.capitalize(s: string): string
|
|||
return (s:gsub("^%l", string.upper))
|
||||
end
|
||||
|
||||
function utils.lowercase(s: string): string
|
||||
return (s:gsub("^%L", string.lower))
|
||||
end
|
||||
|
||||
function utils.is_empty(s: string): boolean
|
||||
return s == nil or s == ""
|
||||
end
|
||||
|
|
|
@ -6,4 +6,5 @@ return {
|
|||
"types",
|
||||
"generated", -- used to remove require error when visualizing the generated type definitions
|
||||
},
|
||||
global_env_def = "generated.global_env", -- used to remove require error when visualizing the generated type definitions
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue