5 million review changes

This commit is contained in:
Chris de Graaf 2017-08-23 12:50:52 -05:00
parent 86d2d5c0fb
commit 2af2407881
16 changed files with 302 additions and 326 deletions

View File

@ -34,4 +34,4 @@ test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"PkgTemplates\"; coverage=true)"
after_test:
- C:\projects\julia\bin\julia -e "cd(Pkg.dir(\"AppVeyorTesting\")); Pkg.add(\"Coverage\"); using Coverage; Codecov.submit(process_folder())"
- C:\projects\julia\bin\julia -e "cd(Pkg.dir(\"PkgTemplates\")); Pkg.add(\"Coverage\"); using Coverage; Codecov.submit(process_folder())"

View File

@ -7,8 +7,6 @@ julia:
- nightly
notifications:
email: false
before_script:
- cp docs/src/assets/invenia.css $HOME
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.test("PkgTemplates"; coverage=true)'

View File

@ -54,7 +54,7 @@ julia> t = Template(;
dir=joinpath(homedir(), "code"),
julia_version=v"0.5.2",
requirements=["PkgTemplates"],
git_config=Dict("diff.renames" => true),
gitconfig=Dict("diff.renames" => true),
plugins=[
TravisCI(),
CodeCov(; config_file=nothing),
@ -102,13 +102,13 @@ And if that's **still** too much work for you, you can call
`interactive_template` with `fast=true` to use default values for everything
but username and plugin selection.
## Comparison to [PkgDev](https://github.com/JuliaLang/PkgDev.jl)
## Comparison to PkgDev
`PkgTemplates` is similar in functionality to `PkgDev`'s `generate` function.
However, `PkgTemplates` offers more customizability in templates and more
extensibility via plugins. For the package registration and release management
features that `PkgTemplates` doesn't include, you are encouraged to use
[AttoBot](https://github.com/apps/attobot) instead.
`PkgTemplates` is similar in functionality to
[`PkgDev`](https://github.com/JuliaLang/PkgDev.jl)'s `generate` function. However,
`PkgTemplates` offers more customizability in templates and more extensibility via plugins.
For the package registration and release management features that `PkgTemplates` doesn't
include, you are encouraged to use [AttoBot](https://github.com/apps/attobot) instead.
## Contributing

View File

@ -14,9 +14,7 @@ makedocs(;
repo="https://github.com/christopher-dG/PkgTemplates.jl/blob/{commit}{path}#L{line}",
sitename="PkgTemplates.jl",
authors="Chris de Graaf, Invenia Technical Computing Corporation",
assets=[
"assets/invenia.css",
],
assets=[],
)
deploydocs(;

View File

@ -1,75 +0,0 @@
/* Links */
a {
color: #4595D1;
}
a:hover, a:focus {
color: #194E82;
}
/* Navigation */
nav.toc ul a:hover,
nav.toc ul.internal a:hover {
color: #FFFFFF;
background-color: #4595D1;
}
nav.toc ul .toctext {
color: #FFFFFF;
}
nav.toc {
box-shadow: none;
color: #FFFFFF;
background-color: #194E82;
}
nav.toc li.current > .toctext {
color: #FFFFFF;
background-color: #4595D1;
border-top-width: 0px;
border-bottom-width: 0px;
}
nav.toc ul.internal a {
color: #194E82;
background-color: #FFFFFF;
}
/* Text */
article#docs a.nav-anchor {
color: #194E82;
}
article#docs blockquote {
font-style: italic;
}
/* Code */
code .hljs-meta {
color: #4595D1;
}
code .hljs-keyword {
color: #194E82;
}
pre, code {
font-family: "Liberation Mono", "Consolas", "DejaVu Sans Mono", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace;
}
/* mkdocs (old) */
/*.navbar-default {
background-color: #194E82;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: #4595D1;
}*/

View File

@ -40,7 +40,7 @@ t = Template(;
dir=joinpath(homedir(), "code"),
julia_version=v"0.5.2",
requirements=["PkgTemplates"],
git_config=Dict("diff.renames" => true),
gitconfig=Dict("diff.renames" => true),
plugins=[
TravisCI(),
CodeCov(; config_file=nothing),

View File

@ -8,6 +8,12 @@ CurrentModule = PkgTemplates
are available for use with `PkgTemplates`, but if you see that one is missing,
don't hesitate to open an issue or PR.
## `available_licenses`
```@docs
available_licenses
```
## `show_license`
```@docs

View File

@ -5,12 +5,12 @@ using Mustache
using TerminalMenus
using URIParser
export generate, interactive_template, show_license, Template, GitHubPages, AppVeyor,
TravisCI, CodeCov, Coveralls
export generate, interactive_template, show_license, available_licenses, Template,
GitHubPages, AppVeyor, TravisCI, CodeCov, Coveralls
abstract type Plugin end
include("license.jl")
include("licenses.jl")
include("template.jl")
include("generate.jl")
include("plugin.jl")
@ -22,17 +22,6 @@ include(joinpath("plugins", "travisci.jl"))
include(joinpath("plugins", "githubpages.jl"))
const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults"))
const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "licenses"))
const LICENSES = Dict(
"MIT" => "MIT \"Expat\" License",
"BSD" => "Simplified \"2-clause\" BSD License",
"ASL" => "Apache License, Version 2.0",
"MPL" => "Mozilla Public License, Version 2.0",
"GPL-2.0+" => "GNU Public License, Version 2.0+",
"GPL-3.0+" => "GNU Public License, Version 3.0+",
"LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+",
"LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+"
)
const BADGE_ORDER = [GitHubPages, TravisCI, AppVeyor, CodeCov, Coveralls]
end

View File

@ -13,8 +13,8 @@ Generate a package names `pkg_name` from `template`.
* `ssh::Bool=false`: Whether or not to use SSH for the remote.
# Notes
The package is generated entirely in a temporary directory (`t.temp_dir`), and only moved
into `joinpath(t.dir, pkg_name)` at the very end. In the case of an error, the temporary
The package is generated entirely in a temporary directory and only moved into
`joinpath(t.dir, pkg_name)` at the very end. In the case of an error, the temporary
directory will contain leftovers, but the destination directory will remain untouched
(this is especially helpful when `force=true`).
"""
@ -23,10 +23,22 @@ function generate(
t::Template;
force::Bool=false,
ssh::Bool=false,
)
mktempdir() do temp_dir
generate(pkg_name, t, temp_dir; force=force, ssh=ssh)
end
end
function generate(
pkg_name::AbstractString,
t::Template,
dir::AbstractString;
force::Bool=false,
ssh::Bool=false,
)
pkg_name = Pkg.splitjl(pkg_name)
pkg_dir = joinpath(t.dir, pkg_name)
temp_pkg_dir = joinpath(t.temp_dir, pkg_name)
temp_pkg_dir = joinpath(dir, pkg_name)
if !force && ispath(pkg_dir)
throw(ArgumentError(
@ -38,8 +50,8 @@ function generate(
repo = LibGit2.init(temp_pkg_dir)
info("Initialized git repo at $temp_pkg_dir")
cfg = LibGit2.GitConfig(repo)
!isempty(t.git_config) && info("Applying git configuration")
for (key, val) in t.git_config
!isempty(t.gitconfig) && info("Applying git configuration")
for (key, val) in t.gitconfig
LibGit2.set!(cfg, key, val)
end
LibGit2.commit(repo, "Empty initial commit")
@ -62,13 +74,13 @@ function generate(
# Generate the files.
files = vcat(
gen_entrypoint(pkg_name, t),
gen_tests(pkg_name, t),
gen_require(temp_pkg_dir, t),
gen_readme(pkg_name, t),
gen_gitignore(pkg_name, t),
gen_license(pkg_name, t),
vcat(collect(gen_plugin(plugin, t, pkg_name) for plugin in values(t.plugins))...),
gen_entrypoint(dir, pkg_name, t),
gen_tests(dir, pkg_name, t),
gen_require(dir, pkg_name, t),
gen_readme(dir, pkg_name, t),
gen_gitignore(dir, pkg_name, t),
gen_license(dir, pkg_name, t),
vcat([gen_plugin(plugin, t, dir, pkg_name) for plugin in values(t.plugins)]...),
)
LibGit2.add!(repo, files...)
@ -78,7 +90,7 @@ function generate(
multiple_branches = length(collect(LibGit2.GitBranchIter(repo))) > 1
info("Moving temporary package directory into $(t.dir)/")
mv(temp_pkg_dir, pkg_dir; remove_destination=force)
rm(t.temp_dir; recursive=true)
info("Finished")
if multiple_branches
warn("Remember to push all created branches to your remote: git push --all")
@ -86,17 +98,23 @@ function generate(
end
"""
gen_entrypoint(pkg_name::AbstractString, template::Template) -> Vector{String}
gen_entrypoint(
dir::AbstractString,
pkg_name::AbstractString,
template::Template,
) -> Vector{String}
Create the module entrypoint in the temp package directory.
# Arguments
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose entrypoint we are generating.
Returns an array of generated file/directory names.
"""
function gen_entrypoint(pkg_name::AbstractString, template::Template)
function gen_entrypoint(dir::AbstractString, pkg_name::AbstractString, template::Template)
text = """
module $pkg_name
@ -105,22 +123,28 @@ function gen_entrypoint(pkg_name::AbstractString, template::Template)
end
"""
gen_file(joinpath(template.temp_dir, pkg_name, "src", "$pkg_name.jl"), text)
gen_file(joinpath(dir, pkg_name, "src", "$pkg_name.jl"), text)
return ["src/"]
end
"""
gen_tests(pkg_name::AbstractString, template::Template) -> Vector{String}
gen_tests(
dir::AbstractString,
pkg_name::AbstractString,
template::Template,
) -> Vector{String}
Create the test directory and entrypoint in the temp package directory.
# Arguments
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose tests we are generating.
Returns an array of generated file/directory names.
"""
function gen_tests(pkg_name::AbstractString, template::Template)
function gen_tests(dir::AbstractString, pkg_name::AbstractString, template::Template)
text = """
using $pkg_name
using Base.Test
@ -129,44 +153,55 @@ function gen_tests(pkg_name::AbstractString, template::Template)
@test 1 == 2
"""
gen_file(joinpath(template.temp_dir, pkg_name, "test", "runtests.jl"), text)
gen_file(joinpath(dir, pkg_name, "test", "runtests.jl"), text)
return ["test/"]
end
"""
gen_require(pkg_name::AbstractString, template::Template) -> Vector{String}
gen_require(
dir::AbstractString,
pkg_name::AbstractString,
template::Template,
) -> Vector{String}
Create the `REQUIRE` file in the temp package directory.
# Arguments
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose REQUIRE we are generating.
Returns an array of generated file/directory names.
"""
function gen_require(pkg_name::AbstractString, template::Template)
function gen_require(dir::AbstractString, pkg_name::AbstractString, template::Template)
text = "julia $(version_floor(template.julia_version))\n"
text *= join(template.requirements, "\n")
gen_file(joinpath(template.temp_dir, pkg_name, "REQUIRE"), text)
gen_file(joinpath(dir, pkg_name, "REQUIRE"), text)
return ["REQUIRE"]
end
"""
gen_readme(pkg_name::AbstractString, template::Template) -> Vector{String}
gen_readme(
dir::AbstractString,
pkg_name::AbstractString,
template::Template,
) -> Vector{String}
Create a README in the temp package directory with badges for each enabled plugin.
# Arguments
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose README we are generating.
Returns an array of generated file/directory names.
"""
function gen_readme(pkg_name::AbstractString, template::Template)
function gen_readme(dir::AbstractString, pkg_name::AbstractString, template::Template)
text = "# $pkg_name\n"
remaining = copy(collect(keys(template.plugins)))
done = []
# Generate the ordered badges first, then add any remaining ones to the right.
for plugin_type in BADGE_ORDER
if haskey(template.plugins, plugin_type)
@ -175,10 +210,10 @@ function gen_readme(pkg_name::AbstractString, template::Template)
badges(template.plugins[plugin_type], template.user, pkg_name),
"\n",
)
deleteat!(remaining, find(p -> p == plugin_type, remaining)[1])
push!(done, plugin_type)
end
end
for plugin_type in remaining
for plugin_type in setdiff(keys(template.plugins), done)
text *= "\n"
text *= join(
badges(template.plugins[plugin_type], template.user, pkg_name),
@ -186,56 +221,67 @@ function gen_readme(pkg_name::AbstractString, template::Template)
)
end
gen_file(joinpath(template.temp_dir, pkg_name, "README.md"), text)
gen_file(joinpath(dir, pkg_name, "README.md"), text)
return ["README.md"]
end
"""
gen_gitignore(pkg_name::AbstractString, template::Template) -> Vector{String}
gen_gitignore(
dir::AbstractString,
pkg_name::AbstractString,
template::Template,
) -> Vector{String}
Create a `.gitignore` in the temp package directory.
# Arguments
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose .gitignore we are generating.
Returns an array of generated file/directory names.
"""
function gen_gitignore(pkg_name::AbstractString, template::Template)
text = ".DS_Store\n"
seen = []
function gen_gitignore(dir::AbstractString, pkg_name::AbstractString, template::Template)
seen = [".DS_Store"]
patterns = vcat([plugin.gitignore for plugin in values(template.plugins)]...)
for pattern in patterns
if !in(pattern, seen)
text *= "$pattern\n"
push!(seen, pattern)
end
end
text = join(seen, "\n")
gen_file(joinpath(template.temp_dir, pkg_name, ".gitignore"), text)
gen_file(joinpath(dir, pkg_name, ".gitignore"), text)
return [".gitignore"]
end
"""
gen_license(pkg_name::AbstractString, template::Template) -> Vector{String}
gen_license(
dir::AbstractString,
pkg_name::AbstractString,
template::Template,
) -> Vector{String}
Create a license in the temp package directory.
# Arguments
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose LICENSE we are generating.
Returns an array of generated file/directory names.
"""
function gen_license(pkg_name::AbstractString, template::Template)
if template.license == nothing
function gen_license(dir::AbstractString, pkg_name::AbstractString, template::Template)
if isempty(template.license)
return String[]
end
text = "Copyright (c) $(template.years) $(template.authors)\n"
text *= read_license(template.license)
gen_file(joinpath(template.temp_dir, pkg_name, "LICENSE"), text)
gen_file(joinpath(dir, pkg_name, "LICENSE"), text)
return ["LICENSE"]
end

View File

@ -1,22 +0,0 @@
"""
show_license([license::AbstractString]; io=STDOUT) -> Void
Show all available license names, or prints the text of `license`.
"""
show_license(; io=STDOUT) = println(io, join(["$k: $v" for (k, v) in LICENSES], "\n"))
show_license(license::AbstractString; io=STDOUT) = println(io, read_license(license))
"""
read_license(licence::AbstractString) -> String
Returns the contents of `license`. Errors if it is not found. Use [`show_license`](@ref) to
view available licenses.
"""
function read_license(license::AbstractString)
path = joinpath(LICENSE_DIR, license)
if isfile(path)
return string(readchomp(path))
else
throw(ArgumentError("License '$license' is not available"))
end
end

42
src/licenses.jl Normal file
View File

@ -0,0 +1,42 @@
const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "licenses"))
const LICENSES = Dict(
"MIT" => "MIT \"Expat\" License",
"BSD" => "Simplified \"2-clause\" BSD License",
"ASL" => "Apache License, Version 2.0",
"MPL" => "Mozilla Public License, Version 2.0",
"GPL-2.0+" => "GNU Public License, Version 2.0+",
"GPL-3.0+" => "GNU Public License, Version 3.0+",
"LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+",
"LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+"
)
"""
available_licenses([io]) -> Void
Print the names of all available licenses.
"""
available_licenses(io::IO) = println(io, join(["$k: $v" for (k, v) in LICENSES], "\n"))
available_licenses() = available_licenses(STDOUT)
"""
show_license([io::IO], license::AbstractString) -> Void
Print the text of `license`.
"""
show_license(io::IO, license::AbstractString) = println(io, read_license(license))
show_license(license::AbstractString) = show_license(STDOUT, license)
"""
read_license(licence::AbstractString) -> String
Returns the contents of `license`. Errors if it is not found. Use [`show_license`](@ref) to
view available licenses.
"""
function read_license(license::AbstractString)
path = joinpath(LICENSE_DIR, license)
if isfile(path)
return string(readchomp(path))
else
throw(ArgumentError("License '$license' is not available"))
end
end

View File

@ -49,7 +49,7 @@ Generic plugins are plugins that add any number of patterns to the generated pac
"https://myplugin.com/{{USER}}/{{PKGNAME}}.jl",
),
],
Dict{String, Any}("YEAR" => Dates.year(now()),
Dict{String, Any}("YEAR" => Dates.year(Dates.today())),
)
end
end
@ -59,9 +59,9 @@ interactive(plugin_type::Type{MyPlugin}) = interactive(plugin_type; file="my-plu
The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by
default, and creates a badge that links to the project on its own site, using the default
substitutions with one addition: `{{YEAR}} => Dates.year(now()`. Since the default config
template file doesn't follow the generic naming convention, we added another `interactive`
method to correct the assumed filename.
substitutions with one addition: `{{YEAR}} => Dates.year(Dates.today())`. Since the default
config template file doesn't follow the generic naming convention, we added another
`interactive` method to correct the assumed filename.
"""
abstract type GenericPlugin <: Plugin end
@ -86,14 +86,15 @@ pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and
function gen_plugin(
plugin::MyPlugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString
)
if plugin.lucky
text = substitute(
"You got lucky with {{PKGNAME}}, {{USER}}!"),
"You got lucky with {{PKGNAME}}, {{USER}}!",
template,
)
gen_file(joinpath(template.temp_dir, ".myplugin.yml"), text)
gen_file(joinpath(dir, ".myplugin.yml"), text)
else
println("Maybe next time.")
end
@ -149,9 +150,6 @@ A `Badge` contains the data necessary to generate a Markdown badge.
hover::AbstractString
image::AbstractString
link::AbstractString
function Badge(hover::AbstractString, image::AbstractString, link::AbstractString)
new(hover, image, link)
end
end
"""
@ -162,20 +160,39 @@ Return `badge`'s data formatted as a Markdown string.
format(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))"
"""
gen_plugin(plugin::Plugin, template::Template, pkg_name::AbstractString) -> Vector{String}
gen_plugin(
plugin::Plugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString
) -> Vector{String}
Generate any files associated with a plugin.
# Arguments
* `plugin::Plugin`: Plugin whose files are being generated.
* `template::Template`: Template configuration.
* `dir::AbstractString`: The directory in which the files will be generated. Note that
this will be joined to `pkg_name`.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of generated file/directory names.
"""
gen_plugin(plugin::Plugin, template::Template, pkg_name::AbstractString) = String[]
function gen_plugin(
plugin::Plugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
return String[]
end
function gen_plugin(plugin::GenericPlugin, template::Template, pkg_name::AbstractString)
function gen_plugin(
plugin::GenericPlugin,
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
src = try
get(plugin.src)
catch
@ -186,7 +203,7 @@ function gen_plugin(plugin::GenericPlugin, template::Template, pkg_name::Abstrac
template;
view=merge(Dict("PKGNAME" => pkg_name), plugin.view),
)
gen_file(joinpath(template.temp_dir, pkg_name, plugin.dest), text)
gen_file(joinpath(dir, pkg_name, plugin.dest), text)
return [plugin.dest]
end
@ -214,16 +231,16 @@ end
interactive(
plugin_type::Type{P <: Plugin};
file::Union{AbstractString, Void}="",
) -> Union{Plugin, Void}
) -> Plugin
Interactively create a plugin of type `plugin_type`, where `file` is the plugin type's
default config template with a non-standard name (for `MyPlugin`, this is anything but
"myplugin.yml").
"""
function interactive(
plugin_type::Type{P};
plugin_type::Type{<:GenericPlugin};
file::Union{AbstractString, Void}="",
) where P <: GenericPlugin
)
plugin_name = String(split(string(plugin_type), ".")[end])
# By default, we expect the default plugin file template for a plugin called
# "MyPlugin" to be called "myplugin.yml".

View File

@ -4,12 +4,17 @@ generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl).
"""
abstract type Documenter <: CustomPlugin end
function gen_plugin(plugin::Documenter, template::Template, pkg_name::AbstractString)
function gen_plugin(
plugin::Documenter,
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
if Pkg.installed("Documenter") == nothing
info("Adding Documenter.jl")
Pkg.add("Documenter")
end
path = joinpath(template.temp_dir, pkg_name)
path = joinpath(dir, pkg_name)
docs_dir = joinpath(path, "docs", "src")
mkpath(docs_dir)
if !isempty(plugin.assets)
@ -52,7 +57,7 @@ function gen_plugin(plugin::Documenter, template::Template, pkg_name::AbstractSt
open(joinpath(docs_dir, "index.md"), "w") do fp
write(fp, "# $pkg_name")
end
readme_path = joinpath(template.temp_dir, pkg_name, "README.md")
readme_path = joinpath(dir, pkg_name, "README.md")
if isfile(readme_path)
cp(readme_path, joinpath(docs_dir, "index.md"), remove_destination=true)
end

View File

@ -38,13 +38,18 @@ function badges(_::GitHubPages, user::AbstractString, pkg_name::AbstractString)
]
end
function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractString)
function gen_plugin(
plugin::GitHubPages,
template::Template,
dir::AbstractString,
pkg_name::AbstractString,
)
invoke(
gen_plugin, Tuple{Documenter, Template, AbstractString},
plugin, template, pkg_name
gen_plugin, Tuple{Documenter, Template, AbstractString, AbstractString},
plugin, template, dir, pkg_name,
)
if haskey(template.plugins, TravisCI)
docs_src = joinpath(template.temp_dir, pkg_name, "docs", "src")
docs_src = joinpath(dir, pkg_name, "docs", "src")
open(joinpath(dirname(docs_src), "make.jl"), "a") do file
write(
file,

View File

@ -5,7 +5,7 @@ Records common information used to generate a package. If you don't wish to manu
create a template, you can use [`interactive_template`](@ref) instead.
# Keyword Arguments
* `user::AbstractString="")`: GitHub username. If left unset, it will try to take the
* `user::AbstractString=""`: GitHub username. If left unset, it will try to take the
value of a supplied git config's "github.user" key, then the global git config's
value. If neither is set, an `ArgumentError` is thrown.
**This is case-sensitive for some plugins, so take care to enter it correctly.**
@ -14,15 +14,16 @@ create a template, you can use [`interactive_template`](@ref) instead.
officially supported and they will cause certain plugins will produce incorrect output.
For example, [`AppVeyor`](@ref)'s badge image will point to a GitHub-specific URL,
regardless of the value of `host`.
* `license::Union{AbstractString, Void}="MIT"`: Name of the package license. If
no license is specified, no license is created. [`show_license`](@ref) can be used to
list all available licenses, or to print out a particular license's text.
* `authors::Union{AbstractString, Array}=""`: Names that appear on the license. Supply a
string for one author, and an array for multiple. Similarly to `user`, it will try to
take the value of a supplied git config's "user.name" key, then the global git config's
value, if it is left unset
* `years::Union{Int, AbstractString}=Dates.year(now())`: Copyright years on the license.
Can be supplied by a number, or a string such as "2016 - 2017".
* `license::AbstractString="MIT"`: Name of the package license. If an empty string is
given, no license is created. [`available_licenses`](@ref) can be used to list all
available licenses, and [`show_license`](@ref) can be used to print out a particular
license's text.
* `authors::Union{AbstractString, Vector{<:AbstractString}}=""`: Names that appear on the
license. Supply a string for one author, and an array for multiple. Similarly to `user`,
it will try to take the value of a supplied git config's "user.name" key, then the global
git config's value, if it is left unset.
* `years::Union{Integer, AbstractString}=Dates.year(Dates.today())`: Copyright years on the
license. Can be supplied by a number, or a string such as "2016 - 2017".
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go.
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
* `requirements::Vector{String}=String[]`: Package requirements. If there are duplicate
@ -30,49 +31,37 @@ create a template, you can use [`interactive_template`](@ref) instead.
an `ArgumentError` is thrown.
Each entry in this array will be copied into the `REQUIRE` file of packages generated
with this template.
* `git_config::Dict{String, String}=Dict{String, String}()`: Git configuration options.
* `gitconfig::Dict{String, String}=Dict{String, String}()`: Git configuration options.
* `plugins::Plugin[]`: A list of `Plugin`s that the package will include.
# Notes
When you create a `Template`, a temporary directory is created with
`mktempdir()`. This directory will be removed after you call [`generate`](@ref).
Creating multiple packages in succession with the same instance of a template will still
work, but there is a miniscule chance of another process sharing the temporary directory,
which could result in the created package repository containing untracked files that
don't belong.
"""
@auto_hash_equals struct Template
user::AbstractString
host::AbstractString
license::Union{AbstractString, Void}
authors::Union{AbstractString, Array}
license::AbstractString
authors::AbstractString
years::AbstractString
dir::AbstractString
temp_dir::AbstractString
julia_version::VersionNumber
requirements::Vector{AbstractString}
git_config::Dict
gitconfig::Dict
plugins::Dict{DataType, Plugin}
function Template(;
user::AbstractString="",
host::AbstractString="https://github.com",
license::Union{AbstractString, Void}="MIT",
authors::Union{AbstractString, Array}="",
years::Union{Int, AbstractString}=Dates.year(now()),
authors::Union{AbstractString, Vector{<:AbstractString}}="",
years::Union{Integer, AbstractString}=Dates.year(Dates.today()),
dir::AbstractString=Pkg.dir(),
julia_version::VersionNumber=VERSION,
requirements::Vector{String}=String[],
git_config::Dict=Dict(),
plugins::Vector{P}=Plugin[],
) where P <: Plugin
requirements::Vector{<:AbstractString}=String[],
gitconfig::Dict=Dict(),
plugins::Vector{<:Plugin}=Plugin[],
)
# If no username was set, look for one in a supplied git config,
# and then in the global git config.
if isempty(user)
user = get(
git_config, "github.user",
LibGit2.getconfig("github.user", ""),
)
user = get(gitconfig, "github.user", LibGit2.getconfig("github.user", ""))
end
if isempty(user)
throw(ArgumentError("No GitHub username found, set one with user=username"))
@ -80,22 +69,20 @@ don't belong.
host = URI(startswith(host, "https://") ? host : "https://$host").host
if license != nothing && !isfile(joinpath(LICENSE_DIR, license))
if !isempty(license) && !isfile(joinpath(LICENSE_DIR, license))
throw(ArgumentError("License '$license' is not available"))
end
# If no author was set, look for one in the supplied git config,
# and then in the global git config.
if isempty(authors)
authors = get(git_config, "user.name", LibGit2.getconfig("user.name", ""))
elseif isa(authors, Array)
authors = get(gitconfig, "user.name", LibGit2.getconfig("user.name", ""))
elseif isa(authors, Vector)
authors = join(authors, ", ")
end
years = string(years)
temp_dir = mktempdir()
requirements_dedup = collect(Set(requirements))
diff = length(requirements) - length(requirements_dedup)
names = [tokens[1] for tokens in split.(requirements_dedup)]
@ -113,8 +100,8 @@ don't belong.
end
new(
user, host, license, authors, years, dir, temp_dir,
julia_version, requirements_dedup, git_config, plugin_dict
user, host, license, authors, years, dir, julia_version,
requirements_dedup, gitconfig, plugin_dict,
)
end
end
@ -157,10 +144,10 @@ function interactive_template(; fast::Bool=false)
else
println("Select a license:")
io = IOBuffer()
show_license(; io=io)
licenses = [nothing => nothing, collect(LICENSES)...]
available_licenses(io)
licenses = ["" => "", collect(LICENSES)...]
menu = RadioMenu(["None", split(String(take!(io)), "\n")...])
# If the user breaks out of the menu with C-c, the result is -1, the absolute
# If the user breaks out of the menu with Ctrl-c, the result is -1, the absolute
# value of which correponds to no license.
licenses[abs(request(menu))].first
end
@ -176,9 +163,9 @@ function interactive_template(; fast::Bool=false)
end
kwargs[:years] = if fast
Dates.year(now())
Dates.year(Dates.today())
else
default_years = Dates.year(now())
default_years = Dates.year(Dates.today())
print("Enter the copyright year(s) [$default_years]: ")
years = readline()
isempty(years) ? default_years : years
@ -209,20 +196,20 @@ function interactive_template(; fast::Bool=false)
String.(split(readline()))
end
kwargs[:git_config] = if fast
kwargs[:gitconfig] = if fast
Dict()
else
git_config = Dict()
gitconfig = Dict()
print("Enter any Git key-value pairs (one at a time, separated by spaces) [None]: ")
while true
tokens = split(readline())
isempty(tokens) && break
if haskey(git_config, tokens[1])
if haskey(gitconfig, tokens[1])
warn("Duplicate key '$(tokens[1])': Replacing old value '$(tokens[2])'")
end
git_config[tokens[1]] = tokens[2]
gitconfig[tokens[1]] = tokens[2]
end
git_config
gitconfig
end
println("Select plugins:")
@ -243,4 +230,4 @@ end
Get all concrete subtypes of `t`.
"""
leaves(t::Type) = isleaftype(t) ? t : vcat(leaves.(subtypes(t))...)
leaves(t::Type)::Vector{DataType} = isleaftype(t) ? [t] : vcat(leaves.(subtypes(t))...)

View File

@ -12,7 +12,7 @@ struct Bar <: CustomPlugin end
struct Baz <: Plugin end
const me = "christopher-dG"
const git_config = Dict(
const gitconfig = Dict(
"user.name" => "Tester McTestFace",
"user.email" => "email@web.site",
"github.user" => "TesterMcTestFace",
@ -20,12 +20,12 @@ const git_config = Dict(
const test_pkg = "TestPkg"
const fake_path = bin(hash("/this/file/does/not/exist"))
const test_file = tempname()
template_text = """
const template_text = """
PKGNAME: {{PKGNAME}}
VERSION: {{VERSION}}}
{{#DOCUMENTER}}Documenter{{/DOCUMENTER}}
{{#CODECOV}}CodeCov{{/CODECOV}}
{{#CODECOV}}Coveralls{{/CODECOV}}
{{#COVERALLS}}Coveralls{{/COVERALLS}}
{{#AFTER}}After{{/AFTER}}
{{#OTHER}}Other{{/OTHER}}
"""
@ -33,77 +33,61 @@ write(test_file, template_text)
@testset "Template creation" begin
t = Template(; user=me)
rm(t.temp_dir; recursive=true)
@test t.user == me
@test t.license == "MIT"
@test t.years == string(Dates.year(Dates.today()))
@test t.authors == LibGit2.getconfig("user.name", "")
@test t.dir == Pkg.dir()
@test t.julia_version == VERSION
@test isempty(t.git_config)
@test isempty(t.gitconfig)
@test isempty(t.plugins)
t = Template(; user=me, license=nothing)
rm(t.temp_dir; recursive=true)
@test t.license == nothing
t = Template(; user=me, license="")
@test t.license == ""
t = Template(; user=me, license="MPL")
rm(t.temp_dir; recursive=true)
@test t.license == "MPL"
t = Template(; user=me, years=2014)
rm(t.temp_dir; recursive=true)
@test t.years == "2014"
t = Template(user=me, years="2014-2015")
rm(t.temp_dir; recursive=true)
@test t.years == "2014-2015"
t = Template(; user=me, authors="Some Guy")
rm(t.temp_dir; recursive=true)
@test t.authors == "Some Guy"
t = Template(; user=me, authors=["Guy", "Gal"])
rm(t.temp_dir; recursive=true)
@test t.authors == "Guy, Gal"
t = Template(; user=me, dir=test_file)
rm(t.temp_dir; recursive=true)
@test t.dir == test_file
t = Template(; user=me, julia_version=v"0.1.2")
rm(t.temp_dir; recursive=true)
@test t.julia_version == v"0.1.2"
t = Template(; user=me, requirements=["$test_pkg 0.1"])
rm(t.temp_dir; recursive=true)
@test t.requirements == ["$test_pkg 0.1"]
@test_warn r".+" t = Template(; user=me, requirements=[test_pkg, test_pkg])
rm(t.temp_dir; recursive=true)
@test t.requirements == [test_pkg]
@test_throws ArgumentError t = Template(;
user=me,
requirements=[test_pkg, "$test_pkg 0.1"]
)
rm(t.temp_dir; force=true, recursive=true)
t = Template(; user=me, git_config=git_config)
rm(t.temp_dir; recursive=true)
@test t.git_config == git_config
t = Template(; user=me, gitconfig=gitconfig)
@test t.gitconfig == gitconfig
t = Template(; user=me, git_config=git_config)
rm(t.temp_dir; recursive=true)
@test t.authors == git_config["user.name"]
t = Template(; user=me, gitconfig=gitconfig)
@test t.authors == gitconfig["user.name"]
t = Template(; git_config=git_config)
rm(t.temp_dir; recursive=true)
@test t.user == git_config["github.user"]
@test t.authors == git_config["user.name"]
t = Template(; gitconfig=gitconfig)
@test t.user == gitconfig["github.user"]
@test t.authors == gitconfig["user.name"]
t = Template(;
user=me,
plugins = [GitHubPages(), TravisCI(), AppVeyor(), CodeCov(), Coveralls()],
)
rm(t.temp_dir; recursive=true)
@test Set(keys(t.plugins)) == Set(
[GitHubPages, TravisCI, AppVeyor, CodeCov, Coveralls]
)
@ -115,7 +99,6 @@ write(test_file, template_text)
user=me,
plugins=[TravisCI(), TravisCI()],
)
rm(t.temp_dir; recursive=true)
if isempty(LibGit2.getconfig("github.user", ""))
@test_throws ArgumentError t = Template()
@ -123,9 +106,7 @@ write(test_file, template_text)
t = Template()
@test t.user == LibGit2.getconfig("github.user", "")
end
rm(t.temp_dir; force=true, recursive=true)
@test_throws ArgumentError t = Template(; user=me, license="FakeLicense")
rm(t.temp_dir; force=true, recursive=true)
end
@testset "Interactive template creation" begin
@ -133,52 +114,49 @@ end
in_read, in_write = redirect_stdin()
write(in_write, "$me\n\n\r\n\n\n\n\n\nd")
t = interactive_template()
rm(t.temp_dir; recursive=true)
@test t.user == me
@test t.host == "github.com"
@test t.license == nothing
@test isempty(t.license)
@test t.authors == LibGit2.getconfig("user.name", "")
@test t.years == string(Dates.year(now()))
@test t.years == string(Dates.year(Dates.today()))
@test t.dir == Pkg.dir()
@test t.julia_version == VERSION
@test isempty(t.requirements)
@test isempty(t.git_config)
@test isempty(t.gitconfig)
@test isempty(t.plugins)
if isempty(LibGit2.getconfig("github.user", ""))
write(in_write, "\n")
@test_throws ArgumentError t = interactive_template()
rm(t.temp_dir; force=true, recursive=true)
end
write(in_write, "$me\ngitlab.com\n$('\x1b')[B\r$me\n2016\n$test_file\n0.5\nX Y\nA B\n\n$('\x1b')[B\r$('\x1b')[B\rd\n\n")
t = interactive_template()
rm(t.temp_dir; recursive=true)
@test t.user == me
@test t.host == "gitlab.com"
# Not sure if the order the licenses are displayed is consistent.
@test t.license != nothing
@test !isempty(t.license)
@test t.authors == me
@test t.years == "2016"
@test t.dir == test_file
@test t.julia_version == v"0.5.0"
@test Set(t.requirements) == Set(["X", "Y"])
@test t.git_config == Dict("A" => "B")
@test t.gitconfig == Dict("A" => "B")
# Like above, not sure which plugins this will generate.
@test length(t.plugins) == 2
write(in_write, "$me\nd")
t = interactive_template(; fast=true)
rm(t.temp_dir; recursive=true)
@test t.user == me
@test t.host == "github.com"
@test t.license == "MIT"
@test t.authors == LibGit2.getconfig("user.name", "")
@test t.years == string(Dates.year(now()))
# I guess this could technically break if it runs on New Year's Eve...
@test t.years == string(Dates.year(Dates.today()))
@test t.dir == Pkg.dir()
@test t.julia_version == VERSION
@test isempty(t.requirements)
@test isempty(t.git_config)
@test isempty(t.gitconfig)
@test isempty(t.plugins)
redirect_stdin(old_stdin)
@ -199,7 +177,7 @@ end
]
@test isempty(p.view)
p = AppVeyor(; config_file=nothing)
@test_throws NullException get(p.src)
@test isnull(p.src)
p = AppVeyor(; config_file=test_file)
@test get(p.src) == test_file
@test_throws ArgumentError p = AppVeyor(; config_file=fake_path)
@ -217,7 +195,7 @@ end
]
@test isempty(p.view)
p = TravisCI(; config_file=nothing)
@test_throws NullException get(p.src)
@test isnull(p.src)
p = TravisCI(; config_file=test_file)
@test get(p.src) == test_file
@test_throws ArgumentError p = TravisCI(; config_file=fake_path)
@ -235,14 +213,14 @@ end
]
@test isempty(p.view)
p = CodeCov(; config_file=nothing)
@test_throws NullException get(p.src)
@test isnull(p.src)
p = CodeCov(; config_file=test_file)
@test get(p.src) == test_file
@test_throws ArgumentError p = CodeCov(; config_file=fake_path)
p = Coveralls()
@test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"]
@test_throws NullException get(p.src)
@test isnull(p.src)
@test p.dest == ".coveralls.yml"
@test p.badges == [
Badge(
@ -253,7 +231,7 @@ end
]
@test isempty(p.view)
p = Coveralls(; config_file=nothing)
@test_throws NullException get(p.src)
@test isnull(p.src)
p = Coveralls(; config_file=test_file)
@test get(p.src) == test_file
@test_throws ArgumentError p = Coveralls(; config_file=fake_path)
@ -267,7 +245,7 @@ end
end
@testset "Badge generation" begin
user = git_config["github.user"]
user = gitconfig["github.user"]
badge = Badge("A", "B", "C")
@test badge.hover == "A"
@ -304,10 +282,11 @@ end
user=me,
license="MPL",
requirements=[test_pkg],
git_config=git_config,
gitconfig=gitconfig,
plugins=[Coveralls(), TravisCI(), CodeCov(), GitHubPages(), AppVeyor()],
)
pkg_dir = joinpath(t.temp_dir, test_pkg)
temp_dir = mktempdir()
pkg_dir = joinpath(temp_dir, test_pkg)
temp_file = tempname()
gen_file(temp_file, "Hello, world")
@ -315,7 +294,7 @@ end
@test readstring(temp_file) == "Hello, world\n"
rm(temp_file)
@test gen_readme(test_pkg, t) == ["README.md"]
@test gen_readme(temp_dir, test_pkg, t) == ["README.md"]
@test isfile(joinpath(pkg_dir, "README.md"))
readme = readchomp(joinpath(pkg_dir, "README.md"))
rm(joinpath(pkg_dir, "README.md"))
@ -331,12 +310,12 @@ end
search(readme, "coveralls").start
# Plugins with badges but not in BADGE_ORDER should appear at the far right side.
t.plugins[Foo] = Foo()
gen_readme(test_pkg, t)
gen_readme(temp_dir, test_pkg, t)
readme = readchomp(joinpath(pkg_dir, "README.md"))
rm(joinpath(pkg_dir, "README.md"))
@test search(readme, "coveralls").start < search(readme, "baz").start
@test gen_gitignore(test_pkg, t) == [".gitignore"]
@test gen_gitignore(temp_dir, test_pkg, t) == [".gitignore"]
@test isfile(joinpath(pkg_dir, ".gitignore"))
gitignore = readstring(joinpath(pkg_dir, ".gitignore"))
rm(joinpath(pkg_dir, ".gitignore"))
@ -347,7 +326,7 @@ end
end
end
@test gen_license(test_pkg, t) == ["LICENSE"]
@test gen_license(temp_dir, test_pkg, t) == ["LICENSE"]
@test isfile(joinpath(pkg_dir, "LICENSE"))
license = readchomp(joinpath(pkg_dir, "LICENSE"))
rm(joinpath(pkg_dir, "LICENSE"))
@ -355,20 +334,20 @@ end
@test contains(license, t.years)
@test contains(license, read_license(t.license))
@test gen_entrypoint(test_pkg, t) == ["src/"]
@test gen_entrypoint(temp_dir, test_pkg, t) == ["src/"]
@test isdir(joinpath(pkg_dir, "src"))
@test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl"))
entrypoint = readchomp(joinpath(pkg_dir, "src", "$test_pkg.jl"))
rm(joinpath(pkg_dir, "src"); recursive=true)
@test contains(entrypoint, "module $test_pkg")
@test gen_require(test_pkg, t) == ["REQUIRE"]
@test gen_require(temp_dir, test_pkg, t) == ["REQUIRE"]
@test isfile(joinpath(pkg_dir, "REQUIRE"))
vf = version_floor(t.julia_version)
@test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf\n$test_pkg"
rm(joinpath(pkg_dir, "REQUIRE"))
@test gen_tests(test_pkg, t) == ["test/"]
@test gen_tests(temp_dir, test_pkg, t) == ["test/"]
@test isdir(joinpath(pkg_dir, "test"))
@test isfile(joinpath(pkg_dir, "test", "runtests.jl"))
runtests = readchomp(joinpath(pkg_dir, "test", "runtests.jl"))
@ -376,11 +355,11 @@ end
@test contains(runtests, "using $test_pkg")
@test contains(runtests, "using Base.Test")
rm(t.temp_dir; recursive=true)
rm(dirname(pkg_dir); recursive=true)
end
@testset "Package generation" begin
t = Template(; user=me)
t = Template(; user=me, gitconfig=gitconfig)
generate(test_pkg, t)
@test isfile(Pkg.dir(test_pkg, "LICENSE"))
@test isfile(Pkg.dir(test_pkg, "README.md"))
@ -393,7 +372,7 @@ end
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
branches = [LibGit2.shortname(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
@test LibGit2.getconfig(repo, "user.name", "") == LibGit2.getconfig("user.name", "")
@test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"]
@test LibGit2.url(remote) == "https://github.com/$me/$test_pkg.jl"
@test in("master", branches)
@test !in("gh-pages", branches)
@ -406,7 +385,7 @@ end
@test LibGit2.url(remote) == "git@github.com:$me/$test_pkg.jl.git"
rm(Pkg.dir(test_pkg); recursive=true)
t = Template(; user=me, host="gitlab.com")
t = Template(; user=me, host="gitlab.com", gitconfig=gitconfig)
generate(test_pkg, t)
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
@ -414,18 +393,19 @@ end
rm(Pkg.dir(test_pkg); recursive=true)
temp_dir = mktempdir()
t = Template(; user=me, dir=temp_dir)
t = Template(; user=me, dir=temp_dir, gitconfig=gitconfig)
generate(test_pkg, t)
@test isdir(joinpath(temp_dir, test_pkg))
rm(temp_dir; recursive=true)
t = Template(;
user=me,
license=nothing,
git_config=git_config,
license="",
gitconfig=gitconfig,
plugins=[AppVeyor(), GitHubPages(), Coveralls(), CodeCov(), TravisCI()],
)
generate(test_pkg, t)
@test isdir(joinpath(Pkg.dir(), test_pkg))
@test !isfile(Pkg.dir(test_pkg, "LICENSE"))
@test isfile(Pkg.dir(test_pkg, ".travis.yml"))
@test isfile(Pkg.dir(test_pkg, ".appveyor.yml"))
@ -435,7 +415,7 @@ end
@test isdir(Pkg.dir(test_pkg, "docs", "src"))
@test isfile(Pkg.dir(test_pkg, "docs", "src", "index.md"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
@test LibGit2.getconfig(repo, "user.name", "") == git_config["user.name"]
@test LibGit2.getconfig(repo, "user.name", "") == gitconfig["user.name"]
branches = [LibGit2.shortname(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
@test in("gh-pages", branches)
@test !LibGit2.isdirty(repo)
@ -447,7 +427,7 @@ end
@test isfile(Pkg.dir(test_pkg, "README.md"))
rm(Pkg.dir(test_pkg); recursive=true)
t = Template(; user=me, plugins=[GitHubPages()])
t = Template(; user=me, gitconfig=gitconfig, plugins=[GitHubPages()])
generate(test_pkg, t)
readme = readstring(Pkg.dir(test_pkg, "README.md"))
index = readstring(Pkg.dir(test_pkg, "docs", "src", "index.md"))
@ -457,10 +437,11 @@ end
@testset "Plugin generation" begin
t = Template(; user=me)
pkg_dir = joinpath(t.temp_dir, test_pkg)
temp_dir = mktempdir()
pkg_dir = joinpath(temp_dir, test_pkg)
p = TravisCI()
@test gen_plugin(p, t, test_pkg) == [".travis.yml"]
@test gen_plugin(p, t, temp_dir, test_pkg) == [".travis.yml"]
@test isfile(joinpath(pkg_dir, ".travis.yml"))
travis = readstring(joinpath(pkg_dir, ".travis.yml"))
@test !contains(travis, "after_success")
@ -469,7 +450,7 @@ end
@test !contains(travis, "Pkg.add(\"Documenter\")")
rm(joinpath(pkg_dir, ".travis.yml"))
t.plugins[CodeCov] = CodeCov()
gen_plugin(p, t, test_pkg)
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, CodeCov)
travis = readstring(joinpath(pkg_dir, ".travis.yml"))
@test contains(travis, "after_success")
@ -478,7 +459,7 @@ end
@test !contains(travis, "Pkg.add(\"Documenter\")")
rm(joinpath(pkg_dir, ".travis.yml"))
t.plugins[Coveralls] = Coveralls()
gen_plugin(p, t, test_pkg)
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, Coveralls)
travis = readstring(joinpath(pkg_dir, ".travis.yml"))
@test contains(travis, "after_success")
@ -487,7 +468,7 @@ end
@test !contains(travis, "Pkg.add(\"Documenter\")")
rm(joinpath(pkg_dir, ".travis.yml"))
t.plugins[GitHubPages] = GitHubPages()
gen_plugin(p, t, test_pkg)
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, GitHubPages)
travis = readstring(joinpath(pkg_dir, ".travis.yml"))
@test contains(travis, "after_success")
@ -496,12 +477,12 @@ end
@test !contains(travis, "Coveralls.submit")
rm(joinpath(pkg_dir, ".travis.yml"))
p = TravisCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".travis.yml"))
@test_throws ArgumentError TravisCI(; config_file=fake_path)
p = AppVeyor()
@test gen_plugin(p, t, test_pkg) == [".appveyor.yml"]
@test gen_plugin(p, t, temp_dir, test_pkg) == [".appveyor.yml"]
@test isfile(joinpath(pkg_dir, ".appveyor.yml"))
appveyor = readstring(joinpath(pkg_dir, ".appveyor.yml"))
@test !contains(appveyor, "coverage=true")
@ -510,7 +491,7 @@ end
@test !contains(appveyor, "Coveralls.submit")
rm(joinpath(pkg_dir, ".appveyor.yml"))
t.plugins[CodeCov] = CodeCov()
gen_plugin(p, t, test_pkg)
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, CodeCov)
appveyor = readstring(joinpath(pkg_dir, ".appveyor.yml"))
@test contains(appveyor, "coverage=true")
@ -519,7 +500,7 @@ end
@test !contains(appveyor, "Coveralls.submit")
rm(joinpath(pkg_dir, ".appveyor.yml"))
t.plugins[Coveralls] = Coveralls()
gen_plugin(p, t, test_pkg)
gen_plugin(p, t, temp_dir, test_pkg)
delete!(t.plugins, Coveralls)
appveyor = readstring(joinpath(pkg_dir, ".appveyor.yml"))
@test contains(appveyor, "coverage=true")
@ -528,21 +509,21 @@ end
@test !contains(appveyor, "Codecov.submit")
rm(joinpath(pkg_dir, ".appveyor.yml"))
p = AppVeyor(; config_file=nothing)
@test isempty(gen_plugin(p, t, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".appveyor.yml"))
@test_throws ArgumentError AppVeyor(; config_file=fake_path)
p = CodeCov()
@test gen_plugin(p, t, test_pkg) == [".codecov.yml"]
@test gen_plugin(p, t, temp_dir, test_pkg) == [".codecov.yml"]
@test isfile(joinpath(pkg_dir, ".codecov.yml"))
rm(joinpath(pkg_dir, ".codecov.yml"))
p = CodeCov(; config_file=nothing)
@test isempty(gen_plugin(p, t, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
@test !isfile(joinpath(pkg_dir, ".codecov.yml"))
@test_throws ArgumentError CodeCov(; config_file=fake_path)
p = GitHubPages()
@test gen_plugin(p, t, test_pkg) == ["docs/"]
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"]
@test isdir(joinpath(pkg_dir, "docs"))
@test isfile(joinpath(pkg_dir, "docs", "make.jl"))
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@ -554,7 +535,7 @@ end
@test index == "# $test_pkg"
rm(joinpath(pkg_dir, "docs"); recursive=true)
p = GitHubPages(; assets=[test_file])
@test gen_plugin(p, t, test_pkg) == ["docs/"]
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(
make,
@ -567,18 +548,18 @@ end
@test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file)))
rm(joinpath(pkg_dir, "docs"); recursive=true)
t.plugins[TravisCI] = TravisCI()
@test gen_plugin(p, t, test_pkg) == ["docs/"]
@test gen_plugin(p, t, temp_dir, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(make, "deploydocs")
rm(joinpath(pkg_dir, "docs"); recursive=true)
@test_throws ArgumentError GitHubPages(; assets=[fake_path])
p = Bar()
@test isempty(gen_plugin(p, t, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
p = Baz()
@test isempty(gen_plugin(p, t, test_pkg))
@test isempty(gen_plugin(p, t, temp_dir, test_pkg))
rm(t.temp_dir; recursive=true)
rm(dirname(pkg_dir); recursive=true)
end
@testset "Version floor" begin
@ -604,7 +585,6 @@ end
@test contains(text, "Other")
t = Template(; user=me)
rm(t.temp_dir; recursive=true)
view["OTHER"] = false
text = substitute(template_text, t; view=view)
@ -626,7 +606,7 @@ end
@test contains(text, "After")
empty!(t.plugins)
t.plugins[CodeCov] = Coveralls()
t.plugins[Coveralls] = Coveralls()
text = substitute(template_text, t; view=view)
@test contains(text, "Coveralls")
@test contains(text, "After")
@ -640,7 +620,7 @@ end
@testset "License display" begin
old_stdout = STDOUT
out_read, out_write = redirect_stdout()
show_license()
available_licenses()
licenses = join(Char(c) for c in readavailable(out_read))
show_license("MIT")
mit = join(Char(c) for c in readavailable(out_read))