feat(generator): implement module_init_definition
This commit is contained in:
parent
a2a11a1379
commit
774be91098
|
@ -1,5 +1,6 @@
|
|||
return {
|
||||
global_env_def = require "generator.global_env_def",
|
||||
teal_type_definitions = require "generator.teal_type_definitions",
|
||||
module_init_definition = require "generator.module_init_definition",
|
||||
snippets = require "generator.snippets",
|
||||
teal_type_definitions = require "generator.teal_type_definitions",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
local Map = require "pl.Map"
|
||||
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!)
|
||||
|
||||
return {
|
||||
# for name, path in requires:iter() do
|
||||
$(name) = require "$(path)",
|
||||
# end -- /for
|
||||
}
|
||||
]]
|
||||
|
||||
local module = {}
|
||||
|
||||
function module.generate_teal(requires: Map<string, string>): string
|
||||
local tmpl_args = {
|
||||
ipairs = ipairs,
|
||||
requires = requires,
|
||||
snippets = snippets,
|
||||
}
|
||||
return utils.do_or_fail(template.substitute, tmpl, tmpl_args)
|
||||
|
||||
end
|
||||
|
||||
return module
|
||||
|
|
@ -125,3 +125,15 @@ filesystem.file_writer.write(
|
|||
generator.global_env_def.generate_teal(global_env_def),
|
||||
property.out_directory .. "/global_env.d.tl"
|
||||
)
|
||||
|
||||
for module, children in tree:iter() do
|
||||
local requires: Map<string, string> = Map()
|
||||
for child in children:iter() do
|
||||
local name = child:gmatch(".*%.(.*)$")()
|
||||
requires:set(name, child)
|
||||
end
|
||||
filesystem.file_writer.write(
|
||||
generator.module_init_definition.generate_teal(requires),
|
||||
property.out_directory .. "/" .. module:gsub("%.", "/") .. ".d.tl"
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue