diff --git a/src/generate.jl b/src/generate.jl index 8f8c500..d51405f 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -23,6 +23,14 @@ function generate( println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))") end + # Replace the authors field with the template's authors. + if !isempty(t.authors) + path = joinpath(pkg_dir, "Project.toml") + project = read(path, String) + authors = string("[", join(map(repr ∘ strip, split(t.authors, ",")), ", "), "]") + write(path, replace(project, r"authors = .*" => "authors = $authors")) + end + if git # Initialize the repo. repo = LibGit2.init(pkg_dir) diff --git a/src/template.jl b/src/template.jl index 4c35d43..3c300a7 100644 --- a/src/template.jl +++ b/src/template.jl @@ -74,7 +74,9 @@ struct Template # If no author was set, look for one in the global git config. if isempty(authors) authors = LibGit2.getconfig("user.name", "") - elseif isa(authors, Vector) + email = LibGit2.getconfig("user.email", "") + isempty(email) || (authors *= " <$email>") + elseif authors isa Vector authors = join(authors, ", ") end diff --git a/test/tests.jl b/test/tests.jl index 74e0e99..4eec9b1 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -39,10 +39,10 @@ write(test_file, template_text) @testset "Template creation" begin # Checking default field assignments. - t = Template(; user=me) + t = Template(; authors="foo", user=me) @test t.user == me @test t.license == "MIT" - @test t.authors == LibGit2.getconfig("user.name", "") + @test t.authors == "foo" @test t.dir == default_dir @test t.julia_version == PkgTemplates.default_version() @test !t.ssh @@ -109,14 +109,14 @@ end pkg_dir = replace(default_dir, homedir() => "~") ver = PkgTemplates.version_floor(PkgTemplates.default_version()) buf = IOBuffer() - t = Template(; user=me) + t = Template(; user=me, authors="foo") show(buf, t) text = String(take!(buf)) expected = """ Template: → User: $me → Host: github.com - → License: MIT ($(LibGit2.getconfig("user.name", "")) $(year(today()))) + → License: MIT (foo $(year(today()))) → Package directory: $pkg_dir → Minimum Julia version: v$ver → SSH remote: No