Make authors a vector, misc tweaks
This commit is contained in:
parent
47ccb10a99
commit
0d3b124c07
@ -28,8 +28,6 @@ export
|
|||||||
Tests,
|
Tests,
|
||||||
TravisCI
|
TravisCI
|
||||||
|
|
||||||
const DEFAULT_VERSION = VersionNumber(VERSION.major)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A plugin to be added to a [`Template`](@ref), which adds some functionality or integration.
|
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)
|
if !isempty(t.authors)
|
||||||
path = joinpath(pkg_dir, "Project.toml")
|
path = joinpath(pkg_dir, "Project.toml")
|
||||||
toml = TOML.parsefile(path)
|
toml = TOML.parsefile(path)
|
||||||
# TODO: authors should probably be kept as a vector.
|
toml["authors"] = t.authors
|
||||||
toml["authors"] = split(t.authors, ",")
|
|
||||||
get!(toml, "compat", Dict())["julia"] = compat_version(t.julia_version)
|
get!(toml, "compat", Dict())["julia"] = compat_version(t.julia_version)
|
||||||
open(io -> TOML.print(io, toml), path, "w")
|
open(io -> TOML.print(io, toml), path, "w")
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# TODO ::IO APIs for easier testing
|
||||||
|
|
||||||
# Printing utils.
|
# Printing utils.
|
||||||
const TAB = repeat(' ', 4)
|
const TAB = repeat(' ', 4)
|
||||||
const HALFTAB = repeat(' ', 2)
|
const HALFTAB = repeat(' ', 2)
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults"))
|
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
|
abstract type BasicPlugin <: Plugin end
|
||||||
|
|
||||||
|
# Compute the path to a default template file in this repository.
|
||||||
default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...)
|
default_file(paths::AbstractString...) = joinpath(DEFAULTS_DIR, paths...)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String}
|
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}()
|
view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}()
|
||||||
|
|
||||||
@ -67,25 +74,23 @@ function badges(p::Plugin, t::Template, pkg_name::AbstractString)
|
|||||||
end
|
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.
|
Generate any files associated with a plugin.
|
||||||
|
`pkg` is the name of the package being generated.
|
||||||
## Arguments
|
|
||||||
* `p::Plugin`: Plugin whose files are being generated.
|
|
||||||
* `t::Template`: Template configuration.
|
|
||||||
* `pkg::AbstractString`: Name of the package.
|
|
||||||
"""
|
"""
|
||||||
gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing
|
gen_plugin(::Plugin, ::Template, ::AbstractString) = nothing
|
||||||
|
|
||||||
function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString)
|
function gen_plugin(p::BasicPlugin, t::Template, pkg::AbstractString)
|
||||||
source(p) === nothing && return
|
src = source(p)
|
||||||
text = render(source(p), view(p, t, pkg); tags=tags(p))
|
src === nothing && return
|
||||||
gen_file(joinpath(t.dir, pkg_name, destination(p)), text)
|
# TODO template rendering code
|
||||||
|
text = render(src, view(p, t, pkg); tags=tags(p))
|
||||||
|
gen_file(joinpath(t.dir, pkg, destination(p)), text)
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
gen_file(file::AbstractString, text::AbstractString) -> Int
|
gen_file(file::AbstractString, text::AbstractString)
|
||||||
|
|
||||||
Create a new file containing some given text.
|
Create a new file containing some given text.
|
||||||
Trailing whitespace is removed, and the file will end with a newline.
|
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)
|
write(file, text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO pls make me better
|
||||||
|
|
||||||
render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags)
|
render_file(file::AbstractString, view, tags) = render_text(read(file, String), view, tags)
|
||||||
|
|
||||||
render_text(text::AbstractString, view, tags) = render(text, view; tags=tags)
|
render_text(text::AbstractString, view, tags) = render(text, view; tags=tags)
|
||||||
@ -120,6 +127,7 @@ const BADGE_ORDER = [
|
|||||||
TravisCI,
|
TravisCI,
|
||||||
AppVeyor,
|
AppVeyor,
|
||||||
GitLabCI,
|
GitLabCI,
|
||||||
|
CirrusCI,
|
||||||
Codecov,
|
Codecov,
|
||||||
Coveralls,
|
Coveralls,
|
||||||
]
|
]
|
||||||
|
@ -15,7 +15,7 @@ source(p::Citation) = p.file
|
|||||||
destination(::Citation) = "CITATION.bib"
|
destination(::Citation) = "CITATION.bib"
|
||||||
|
|
||||||
view(::Citation, t::Template, pkg::AbstractString) = Dict(
|
view(::Citation, t::Template, pkg::AbstractString) = Dict(
|
||||||
"AUTHORS" => t.authors,
|
"AUTHORS" => join(t.authors, ", "),
|
||||||
"MONTH" => month(today()),
|
"MONTH" => month(today()),
|
||||||
"PKG" => pkg,
|
"PKG" => pkg,
|
||||||
"URL" => "https://$(t.host)/$(t.user)/$pkg.jl",
|
"URL" => "https://$(t.host)/$(t.user)/$pkg.jl",
|
||||||
|
@ -60,7 +60,7 @@ badges(::Documenter{GitLabCI}) = Badge(
|
|||||||
|
|
||||||
view(p::Documenter, t::Template, pkg::AbstractString) = Dict(
|
view(p::Documenter, t::Template, pkg::AbstractString) = Dict(
|
||||||
"ASSETS" => p.assets,
|
"ASSETS" => p.assets,
|
||||||
"AUTHORS" => t.authors,
|
"AUTHORS" => join(t.authors, ", "),
|
||||||
"CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg),
|
"CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg),
|
||||||
"HAS_ASSETS" => !isempty(p.assets),
|
"HAS_ASSETS" => !isempty(p.assets),
|
||||||
"MAKEDOCS_KWARGS" => map((k, v) -> k => repr(v), collect(p.makedocs_kwargs)),
|
"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)))
|
read_license(license::AbstractString) = string(readchomp(license_path(license)))
|
||||||
|
|
||||||
function render_plugin(p::License, t::Template)
|
function render_plugin(p::License, t::Template)
|
||||||
text = "Copyright (c) $(year(today())) $(t.authors)\n"
|
date = year(today())
|
||||||
license = read(p.path, String)
|
authors = join(t.authors, ", ")
|
||||||
startswith(license, "\n") || (text *= "\n")
|
text = "Copyright (c) $date $authors\n\n"
|
||||||
|
license = strip(read(p.path, String))
|
||||||
return text * license
|
return text * license
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
default_version() = VersionNumber(VERSION.major)
|
const DEFAULT_VERSION = VersionNumber(VERSION.major)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Template(interactive::Bool=false; kwargs...) -> Template
|
Template(interactive::Bool=false; kwargs...) -> Template
|
||||||
@ -34,7 +34,7 @@ Records common information used to generate a package.
|
|||||||
struct Template
|
struct Template
|
||||||
user::String
|
user::String
|
||||||
host::String
|
host::String
|
||||||
authors::String
|
authors::Vector{String}
|
||||||
dir::String
|
dir::String
|
||||||
julia_version::VersionNumber
|
julia_version::VersionNumber
|
||||||
ssh::Bool
|
ssh::Bool
|
||||||
@ -46,6 +46,7 @@ end
|
|||||||
|
|
||||||
Template(; interactive::Bool=false, kwargs...) = make_template(Val(interactive); kwargs...)
|
Template(; interactive::Bool=false, kwargs...) = make_template(Val(interactive); kwargs...)
|
||||||
|
|
||||||
|
# Non-interactive Template constructor.
|
||||||
function make_template(::Val{false}; kwargs...)
|
function make_template(::Val{false}; kwargs...)
|
||||||
user = getkw(kwargs, :user)
|
user = getkw(kwargs, :user)
|
||||||
if isempty(user)
|
if isempty(user)
|
||||||
@ -56,7 +57,7 @@ function make_template(::Val{false}; kwargs...)
|
|||||||
host = URI(occursin("://", host) ? host : "https://$host").host
|
host = URI(occursin("://", host) ? host : "https://$host").host
|
||||||
|
|
||||||
authors = getkw(kwargs, :authors)
|
authors = getkw(kwargs, :authors)
|
||||||
authors isa Vector && (authors = join(authors, ", "))
|
authors isa Vector || (authors = map(strip, split(authors, ",")))
|
||||||
|
|
||||||
dir = abspath(expanduser(getkw(kwargs, :dir)))
|
dir = abspath(expanduser(getkw(kwargs, :dir)))
|
||||||
|
|
||||||
@ -82,10 +83,13 @@ function make_template(::Val{false}; kwargs...)
|
|||||||
)
|
)
|
||||||
end
|
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))
|
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)
|
getkw(kwargs, k) = get(() -> defaultkw(k), kwargs, k)
|
||||||
|
|
||||||
|
# Default Template keyword values.
|
||||||
defaultkw(s::Symbol) = defaultkw(Val(s))
|
defaultkw(s::Symbol) = defaultkw(Val(s))
|
||||||
defaultkw(::Val{:user}) = LibGit2.getconfig("github.user", "")
|
defaultkw(::Val{:user}) = LibGit2.getconfig("github.user", "")
|
||||||
defaultkw(::Val{:host}) = "https://github.com"
|
defaultkw(::Val{:host}) = "https://github.com"
|
||||||
@ -103,5 +107,5 @@ function defaultkw(::Val{:authors})
|
|||||||
isempty(name) && return ""
|
isempty(name) && return ""
|
||||||
author = name * " "
|
author = name * " "
|
||||||
isempty(email) || (author *= "<$email>")
|
isempty(email) || (author *= "<$email>")
|
||||||
return strip(author)
|
return [strip(author)]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user