Make authors a vector, misc tweaks
This commit is contained in:
parent
47ccb10a99
commit
0d3b124c07
@ -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.
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,5 @@
|
||||
# TODO ::IO APIs for easier testing
|
||||
|
||||
# Printing utils.
|
||||
const TAB = repeat(' ', 4)
|
||||
const HALFTAB = repeat(' ', 2)
|
||||
|
@ -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,
|
||||
]
|
||||
|
@ -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",
|
||||
|
@ -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)),
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user