Why generate files at all? Julia has built-in metaprogramming where you can just generate the AST and eval it. (Modulo the usual caveat to be wary of metaprogramming.)
And you don’t have to do this ahead of time. You can do all the generation in the package code itself, e.g.
module Foo
include("generator.jl")
generate_and_eval_stuff()
...
end
This will only happen once while the package is being precompiled, so in practice the overhead of code generation is unlikely to be a problem.