diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 3e67469..fe4bc4a 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -28,8 +28,6 @@ export Tests, TravisCI -const DEFAULT_VERSION = VersionNumber(VERSION.major) - """ A plugin to be added to a [`Template`](@ref), which adds some functionality or integration. """ diff --git a/src/generate.jl b/src/generate.jl index 276f1b3..3e7f9ce 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -16,8 +16,7 @@ function (t::Template)(pkg::AbstractString) if !isempty(t.authors) path = joinpath(pkg_dir, "Project.toml") toml = TOML.parsefile(path) - # TODO: authors should probably be kept as a vector. - toml["authors"] = split(t.authors, ",") + toml["authors"] = t.authors get!(toml, "compat", Dict())["julia"] = compat_version(t.julia_version) open(io -> TOML.print(io, toml), path, "w") end diff --git a/src/interactive.jl b/src/interactive.jl index 230393c..c6d5f67 100644 --- a/src/interactive.jl +++ b/src/interactive.jl @@ -1,3 +1,5 @@ +# TODO ::IO APIs for easier testing + # Printing utils. const TAB = repeat(' ', 4) const HALFTAB = repeat(' ', 2) diff --git a/src/licenses.jl b/src/licenses.jl deleted file mode 100644 index e69de29..0000000 diff --git a/src/plugin.jl b/src/plugin.jl index 9abb6b6..bf872fe 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,13 +1,20 @@ const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) +""" +A simple plugin that, in general, manages a single file. +For example, most CI services reply on one configuration file. + +TODO: Dev guide. +""" abstract type BasicPlugin <: Plugin end +# Compute the path to a default template file in this repository. default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...) """ view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String} -Return extra string substitutions to be made for this plugin. +Return the string replacements to be made for this plugin. """ view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() @@ -67,25 +74,23 @@ function badges(p::Plugin, t::Template, pkg_name::AbstractString) end """ - gen_plugin(p::Plugin, t::Template, pkg::AbstractString) -> Nothing + gen_plugin(p::Plugin, t::Template, pkg::AbstractString) Generate any files associated with a plugin. - -## Arguments -* `p::Plugin`: Plugin whose files are being generated. -* `t::Template`: Template configuration. -* `pkg::AbstractString`: Name of the package. +`pkg` is the name of the package being generated. """ gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) - source(p) === nothing && return - text = render(source(p), view(p, t, pkg); tags=tags(p)) - gen_file(joinpath(t.dir, pkg_name, destination(p)), text) + src = source(p) + src === nothing && return + # TODO template rendering code + text = render(src, view(p, t, pkg); tags=tags(p)) + gen_file(joinpath(t.dir, pkg, destination(p)), text) end """ - gen_file(file::AbstractString, text::AbstractString) -> Int + gen_file(file::AbstractString, text::AbstractString) Create a new file containing some given text. Trailing whitespace is removed, and the file will end with a newline. @@ -97,6 +102,8 @@ function gen_file(file::AbstractString, text::AbstractString) write(file, text) end +# TODO pls make me better + render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags) render_text(text::AbstractString, view, tags) = render(text, view; tags=tags) @@ -120,6 +127,7 @@ const BADGE_ORDER = [ TravisCI, AppVeyor, GitLabCI, + CirrusCI, Codecov, Coveralls, ] diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 8d3e2a4..82e2708 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -15,7 +15,7 @@ source(p::Citation) = p.file destination(::Citation) = "CITATION.bib" view(::Citation, t::Template, pkg::AbstractString) = Dict( - "AUTHORS" => t.authors, + "AUTHORS" => join(t.authors, ", "), "MONTH" => month(today()), "PKG" => pkg, "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index 5b6c019..064c98c 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -60,7 +60,7 @@ badges(::Documenter{GitLabCI}) = Badge( view(p::Documenter, t::Template, pkg::AbstractString) = Dict( "ASSETS" => p.assets, - "AUTHORS" => t.authors, + "AUTHORS" => join(t.authors, ", "), "CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg), "HAS_ASSETS" => !isempty(p.assets), "MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)), diff --git a/src/plugins/essentials.jl b/src/plugins/essentials.jl index e0db4fd..5b43a44 100644 --- a/src/plugins/essentials.jl +++ b/src/plugins/essentials.jl @@ -63,9 +63,10 @@ end read_license(license::AbstractString) = string(readchomp(license_path(license))) function render_plugin(p::License, t::Template) - text = "Copyright (c) $(year(today())) $(t.authors)\n" - license = read(p.path, String) - startswith(license, "\n") || (text *= "\n") + date = year(today()) + authors = join(t.authors, ", ") + text = "Copyright (c) $date $authors\n\n" + license = strip(read(p.path, String)) return text * license end diff --git a/src/template.jl b/src/template.jl index 8fa59c7..98628ee 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,4 +1,4 @@ -default_version() = VersionNumber(VERSION.major) +const DEFAULT_VERSION = VersionNumber(VERSION.major) """ Template(interactive::Bool=false; kwargs...) -> Template @@ -34,7 +34,7 @@ Records common information used to generate a package. struct Template user::String host::String - authors::String + authors::Vector{String} dir::String julia_version::VersionNumber ssh::Bool @@ -46,6 +46,7 @@ end Template(; interactive::Bool=false, kwargs...) = make_template(Val(interactive); kwargs...) +# Non-interactive Template constructor. function make_template(::Val{false}; kwargs...) user = getkw(kwargs, :user) if isempty(user) @@ -56,7 +57,7 @@ function make_template(::Val{false}; kwargs...) host = URI(occursin("://", host) ? host : "https://$host").host authors = getkw(kwargs, :authors) - authors isa Vector && (authors = join(authors, ", ")) + authors isa Vector || (authors = map(strip, split(authors, ","))) dir = abspath(expanduser(getkw(kwargs, :dir))) @@ -82,10 +83,13 @@ function make_template(::Val{false}; kwargs...) ) end +# Does the template have a plugin of this type? Subtypes count too. hasplugin(t::Template, ::Type{T}) where T <: Plugin = any(U -> U <: T, keys(t.plugins)) +# Get a keyword, or compute some default value. getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k) +# Default Template keyword values. defaultkw(s::Symbol) = defaultkw(Val(s)) defaultkw(::Val{:user}) = LibGit2.getconfig("github.user", "") defaultkw(::Val{:host}) = "https://github.com" @@ -103,5 +107,5 @@ function defaultkw(::Val{:authors}) isempty(name) && return "" author = name * " " isempty(email) || (author *= "<$email>") - return strip(author) + return [strip(author)] end