Allow disabling of config file generation

This commit is contained in:
Chris de Graaf 2017-08-11 22:36:29 -05:00
parent e18d4a2751
commit 3866caffc9
7 changed files with 129 additions and 96 deletions

View File

@ -77,7 +77,7 @@ Generate a README with badges for each enabled plugin.
* `pkg_dir::AbstractString`: The package directory. * `pkg_dir::AbstractString`: The package directory.
* `t::Template`: The template whose README we are generating. * `t::Template`: The template whose README we are generating.
Returns the name of the generated file "README.md" for git-add. Returns the name of the generated file.
""" """
function gen_readme(pkg_dir::AbstractString, t::Template) function gen_readme(pkg_dir::AbstractString, t::Template)
pkg_name = basename(pkg_dir) pkg_name = basename(pkg_dir)
@ -104,7 +104,7 @@ Generate a .gitignore from the list of enabled `plugins`.
* `pkg_dir::AbstractString`: The package directory. * `pkg_dir::AbstractString`: The package directory.
* `plugins::Dict{DataType, Plugin}`: The enabled plugins. * `plugins::Dict{DataType, Plugin}`: The enabled plugins.
Returns the name of the generated file ".gitignore" for git-add. Returns the name of the generated file.
""" """
function gen_gitignore(pkg_dir::AbstractString, plugins::Dict{DataType,Plugin}) function gen_gitignore(pkg_dir::AbstractString, plugins::Dict{DataType,Plugin})
text = ".DS_Store\n" text = ".DS_Store\n"
@ -119,7 +119,7 @@ function gen_gitignore(pkg_dir::AbstractString, plugins::Dict{DataType,Plugin})
end end
""" """
gen_license(pkg_dir, license, authors, years) -> String gen_license(pkg_dir, license, authors, years) -> Union{String, Void}
Creates a license file for the package. Creates a license file for the package.
@ -129,7 +129,8 @@ Creates a license file for the package.
* `authors::AbstractString`: Author, or comma-delimited list of authors, of the package. * `authors::AbstractString`: Author, or comma-delimited list of authors, of the package.
* `years::AbstractString`: Copyright year or range of copyright years. * `years::AbstractString`: Copyright year or range of copyright years.
Returns the name of the generated file "LICENSE" for git-add. Returns the name of the generated file, or `nothing` in the case that
no license is generated.
""" """
function gen_license( function gen_license(
pkg_dir::AbstractString, pkg_dir::AbstractString,
@ -156,7 +157,7 @@ Creates the module entrypoint ("src/\$pkg_name.jl") in `pkg_dir`.
# Arguments # Arguments
* `pkg_dir::AbstractString`: The package directory. * `pkg_dir::AbstractString`: The package directory.
Returns the name of the generated directory "src/" for git-add. Returns the name of the generated directory.
""" """
function gen_entrypoint(pkg_dir::AbstractString) function gen_entrypoint(pkg_dir::AbstractString)
pkg_name = basename(pkg_dir) pkg_name = basename(pkg_dir)
@ -181,7 +182,7 @@ Create the requirements file in the package directory.
* `pkg_dir::AbstractString`: The package directory. * `pkg_dir::AbstractString`: The package directory.
* `julia_version::VersionNumber`: The minimum Julia version to support. * `julia_version::VersionNumber`: The minimum Julia version to support.
Returns the name of the generated file "REQUIRE" for git-add. Returns the name of the generated file.
""" """
function gen_require(pkg_dir::AbstractString, julia_version::VersionNumber) function gen_require(pkg_dir::AbstractString, julia_version::VersionNumber)
text = "julia $(version_floor(julia_version))\n" text = "julia $(version_floor(julia_version))\n"
@ -198,7 +199,7 @@ Creates the test file "test/runtests.jl" in the package directory.
# Arguments # Arguments
* `pkg_dir::AbstractString`: The package directory. * `pkg_dir::AbstractString`: The package directory.
Returns the name of the generated directory "test/" for git-add. Returns the name of the generated directory.
""" """
function gen_tests(pkg_dir::AbstractString) function gen_tests(pkg_dir::AbstractString)
text = """ text = """
@ -256,7 +257,7 @@ end
template::AbstractString, template::AbstractString,
pkg_name::AbstractString, pkg_name::AbstractString,
pkg_template::Template; pkg_template::Template;
view::Dict{String, String}=Dict{String, String}(), view::Dict{String, Any}=Dict{String, Any}(),
) )
Replace placeholders in `template`. The input string is not modified. Replace placeholders in `template`. The input string is not modified.
@ -265,7 +266,7 @@ Replace placeholders in `template`. The input string is not modified.
* `template::AbstractString`: Template string to make replacements in. * `template::AbstractString`: Template string to make replacements in.
* `pkg_name::AbstractString`: Name of the package being created. * `pkg_name::AbstractString`: Name of the package being created.
* `pkg_template::Template`: The package template in use. * `pkg_template::Template`: The package template in use.
* `view::Dict{String, String}=Dict{String, String}()`: Additional values to be substituted. * `view::Dict{String, Any}=Dict{String, Any}()`: Additional values to be substituted.
Returns the text with substitutions applied. Returns the text with substitutions applied.
""" """

View File

@ -1,23 +1,25 @@
""" """
AppVeyor(;config_file::AbstractString="") -> AppVeyor AppVeyor(; config_file::AbstractString="") -> AppVeyor
Add AppVeyor to a template's plugins to add AppVeyor support. AppVeyor is compatible with Add AppVeyor to a template's plugins to add AppVeyor CI support.
any remote.
# Arguments: # Keyword Arguments
* `config_file::AbstractString`: Absolute or relative path to a custom `.codecov.yml`. * `config_file::Union{AbstractString, Void}`: Path to a custom `.appveyor.yml`.
If `nothing` is supplied, then no file will be generated.
""" """
struct AppVeyor <: Plugin struct AppVeyor <: Plugin
gitignore_files::Vector{AbstractString} gitignore_files::Vector{AbstractString}
config_file::AbstractString config_file::Union{AbstractString, Void}
function AppVeyor(;config_file::AbstractString="") function AppVeyor(; config_file::Union{AbstractString, Void}="")
config_file = isempty(config_file) ? if config_file != nothing
joinpath(DEFAULTS_DIR, "appveyor.yml") : config_file if isempty(config_file)
config_file = joinpath(DEFAULTS_DIR, "appveyor.yml")
end
if !isfile(abspath(config_file)) if !isfile(abspath(config_file))
throw(ArgumentError("File $config_file does not exist")) throw(ArgumentError("File $config_file does not exist"))
end end
end
new(AbstractString[], config_file) new(AbstractString[], config_file)
end end
end end
@ -28,14 +30,16 @@ function ==(a::AppVeyor, b::AppVeyor)
end end
""" """
badges(plugin::AppVeyor, pkg_name::AbstractString, t::Template) -> String badges(plugin::AppVeyor, pkg_name::AbstractString, t::Template) -> Vector{String}
Return Markdown badges for the current package. Generate Markdown badges for the current package.
# Arguments # Arguments
* `plugin::AppVeyor`: plugin whose badges we are generating. * `plugin::AppVeyor`: Plugin whose badges we are generating.
* `t::Template`: Template configuration options. * `t::Template`: Template configuration options.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of Markdown badges.
""" """
function badges(plugin::AppVeyor, t::Template, pkg_name::AbstractString) function badges(plugin::AppVeyor, t::Template, pkg_name::AbstractString)
user = strip(URI(t.remote_prefix).path, '/') user = strip(URI(t.remote_prefix).path, '/')
@ -45,7 +49,7 @@ function badges(plugin::AppVeyor, t::Template, pkg_name::AbstractString)
end end
""" """
gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString) gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString) -> Vector{String}
Generate a .appveyor.yml. Generate a .appveyor.yml.
@ -54,9 +58,12 @@ Generate a .appveyor.yml.
* `template::Template`: Template configuration and plugins. * `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files ([".appveyor.yml"]) for git to add. Returns an array of generated files.
""" """
function gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString) function gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
text = substitute(readstring(plugin.config_file), pkg_name, template) text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name) pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".appveyor.yml"), text) gen_file(joinpath(pkg_dir, ".appveyor.yml"), text)

View File

@ -1,21 +1,25 @@
""" """
CodeCov(;config_file::AbstractString="") -> CodeCov CodeCov(; config_file::AbstractString="") -> CodeCov
Add CodeCov to a template's plugins to enable CodeCov coverage reports. Add CodeCov to a template's plugins to enable CodeCov coverage reports.
# Keyword Arguments: # Keyword Arguments:
* `config_file::AbstractString`: Path to a custom `.codecov.yml`. * `config_file::AbstractString`: Path to a custom `.codecov.yml`.
If `nothing` is supplied, then no file will be generated.
""" """
struct CodeCov <: Plugin struct CodeCov <: Plugin
gitignore_files::Vector{AbstractString} gitignore_files::Vector{AbstractString}
config_file::AbstractString config_file::AbstractString
function CodeCov(;config_file::AbstractString="") function CodeCov(; config_file::AbstractString="")
config_file = isempty(config_file) ? if config_file != nothing
joinpath(DEFAULTS_DIR, "codecov.yml") : config_file if isempty(config_file)
config_file = joinpath(DEFAULTS_DIR, "codecov.yml")
end
if !isfile(abspath(config_file)) if !isfile(abspath(config_file))
throw(ArgumentError("File $config_file does not exist")) throw(ArgumentError("File $config_file does not exist"))
end end
end
new(["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], config_file) new(["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], config_file)
end end
end end
@ -26,14 +30,16 @@ function ==(a::CodeCov, b::CodeCov)
end end
""" """
badges(plugin::CodeCov, pkg_name::AbstractString, t::Template) -> String badges(plugin::CodeCov, pkg_name::AbstractString, t::Template) -> Vector{String}
Return Markdown badges for the current package. Generate Markdown badges for the current package.
# Arguments # Arguments
* `plugin::CodeCov`: plugin whose badges we are generating. * `plugin::CodeCov`: plugin whose badges we are generating.
* `t::Template`: Template configuration options. * `t::Template`: Template configuration options.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of Markdown badges.
""" """
function badges(plugin::CodeCov, t::Template, pkg_name::AbstractString) function badges(plugin::CodeCov, t::Template, pkg_name::AbstractString)
user = strip(URI(t.remote_prefix).path, '/') user = strip(URI(t.remote_prefix).path, '/')
@ -43,7 +49,7 @@ function badges(plugin::CodeCov, t::Template, pkg_name::AbstractString)
end end
""" """
gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) -> Vector{String}
Generate a .codecov.yml. Generate a .codecov.yml.
@ -52,9 +58,12 @@ Generate a .codecov.yml.
* `template::Template`: Template configuration and plugins. * `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files ([".codecov.yml"]) for git to add. Returns an array of generated files.
""" """
function gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString) function gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
text = substitute(readstring(plugin.config_file), pkg_name, template) text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name) pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".codecov.yml"), text) gen_file(joinpath(pkg_dir, ".codecov.yml"), text)

View File

@ -6,8 +6,10 @@ Docker image containing the package.
# Keyword Arguments # Keyword Arguments
* `base_image::AbstractString="julia:latest"`: The base image used in the Dockerfile. * `base_image::AbstractString="julia:latest"`: The base image used in the Dockerfile.
* `dockerfile_file::AbstractString=""`: the path to the Dockerfile template to use. * `dockerfile_file::Union{AbstractString, Void}=""`: The path to the Dockerfile template
* `dockerignore_file::AbstractString=""`: the path to the .dockerignore template to use. to use. If `nothing` is supplied, then no file will be generated.
* `dockerignore_file::Union{AbstractString, Void}=""`: The path to the .dockerignore
template to use. If `nothing` is supplied, then no file will be generated.
* `system_pkgs::Vector{AbstractString}=String[]`: Linux system packages to install. * `system_pkgs::Vector{AbstractString}=String[]`: Linux system packages to install.
* `python_pkgs::Vector{AbstractString}=String[]`: Python packages to install with `pip`. * `python_pkgs::Vector{AbstractString}=String[]`: Python packages to install with `pip`.
* `user_image::Bool=true`: Allows the Dockerfile to build a Julia system image which * `user_image::Bool=true`: Allows the Dockerfile to build a Julia system image which
@ -33,25 +35,29 @@ struct Docker <: Plugin
function Docker(; function Docker(;
base_image="julia:latest", base_image="julia:latest",
dockerfile_file::AbstractString="", dockerfile_file::Union{AbstractString, Void}="",
dockerignore_file::AbstractString="", dockerignore_file::Union{AbstractString, Void}="",
user_image::Bool=true, user_image::Bool=true,
system_pkgs=String[], system_pkgs::Vector{AbstractString}=String[],
python_pkgs=String[], python_pkgs::Vector{AbstractString}=String[],
) )
if dockerfile_file != nothing
if isempty(dockerfile_file) if isempty(dockerfile_file)
dockerfile_file = joinpath(DEFAULTS_DIR, "Dockerfile") dockerfile_file = joinpath(DEFAULTS_DIR, "Dockerfile")
end end
if !isfile(dockerfile_file) if !isfile(dockerfile_file)
throw(ArgumentError("File $dockerfile_file does not exist")) throw(ArgumentError("File $dockerfile_file does not exist"))
end end
end
if dockerignore_file != nothing
if isempty(dockerignore_file) if isempty(dockerignore_file)
dockerignore_file = joinpath(DEFAULTS_DIR, "dockerignore") dockerignore_file = joinpath(DEFAULTS_DIR, "dockerignore")
end end
if !isfile(dockerignore_file) if !isfile(dockerignore_file)
throw(ArgumentError("File $dockerignore_file does not exist")) throw(ArgumentError("File $dockerignore_file does not exist"))
end end
end
new( new(
base_image, dockerfile_file, dockerignore_file, base_image, dockerfile_file, dockerignore_file,
@ -61,7 +67,7 @@ struct Docker <: Plugin
end end
""" """
gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString) gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString) -> Vector{String}
Generate a Dockerfile for running an app-style package and generate dependency files of Generate a Dockerfile for running an app-style package and generate dependency files of
different sorts for installation within a Docker container. different sorts for installation within a Docker container.
@ -72,14 +78,20 @@ different sorts for installation within a Docker container.
* `template::Template`: Template configuration and plugins. * `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files for git to add. Returns an array of generated files.
""" """
function gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString) function gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString)
pkg_dir = joinpath(template.path, pkg_name) pkg_dir = joinpath(template.path, pkg_name)
return_files = String[]
if plugin.dockerignore_file != nothing
push!(return_files, ".dockerignore")
text = substitute(readstring(plugin.dockerignore_file), pkg_name, template) text = substitute(readstring(plugin.dockerignore_file), pkg_name, template)
gen_file(joinpath(pkg_dir, ".dockerignore"), text) gen_file(joinpath(pkg_dir, ".dockerignore"), text)
end
if plugin.dockerfile_file != nothing
push!(return_files, "Dockerfile")
view = Dict( view = Dict(
"BASE_IMAGE" => plugin.base_image, "BASE_IMAGE" => plugin.base_image,
"MAINTAINER" => template.authors, "MAINTAINER" => template.authors,
@ -89,11 +101,7 @@ function gen_plugin(plugin::Docker, template::Template, pkg_name::AbstractString
) )
text = substitute(readstring(plugin.dockerfile_file), pkg_name, template, view) text = substitute(readstring(plugin.dockerfile_file), pkg_name, template, view)
gen_file(joinpath(pkg_dir, "Dockerfile"), text) gen_file(joinpath(pkg_dir, "Dockerfile"), text)
end
return_files = String[
".dockerignore",
"Dockerfile",
]
pkg_lists = Dict( pkg_lists = Dict(
"system-pkgs.txt" => plugin.system_pkgs, "system-pkgs.txt" => plugin.system_pkgs,

View File

@ -1,38 +1,37 @@
""" """
GitHubPages(css_files::Union{String, Vector{AbstractString}}=String[]) -> GitHubPages GitHubPages(; documenter_assets::Vector{AbstractString}=String[]) -> GitHubPages
Add GitHubPages to a template's plugins to add Documenter.jl support via GitHub Pages. Add GitHubPages to a template's plugins to add Documenter.jl support via GitHub Pages.
# Keyword Arguments # Keyword Arguments
* `css_files::Union{String, Vector{String}}=String[]`: Array of paths to custom CSS files. * `documenter_assets::Vector{String}=String[]`: Array of paths to Documenter asset files.
""" """
struct GitHubPages <: Documenter struct GitHubPages <: Documenter
gitignore_files::Vector{AbstractString} gitignore_files::Vector{AbstractString}
css_files::Vector{AbstractString} documenter_assets::Vector{AbstractString}
function GitHubPages(;css_files::Union{String, Vector{String}}=String[]) function GitHubPages(; css_files::Vector{String}=String[])
if isa(css_files, String) for file in documenter_assets
css_files = [css_files]
end
for file in css_files
if !isfile(file) if !isfile(file)
throw(ArgumentError("Asset file $file does not exist")) throw(ArgumentError("Asset file $file does not exist"))
end end
end end
# Windows Git recognizes these paths as well. # Windows Git recognizes these paths as well.
new(["/docs/build/", "/docs/site/"], css_files) new(["/docs/build/", "/docs/site/"], documenter_assets)
end end
end end
""" """
badges(plugin::GitHubPages, pkg_name::AbstractString, t::Template) -> Vector{String} badges(plugin::GitHubPages, pkg_name::AbstractString, t::Template) -> Vector{String}
Return Markdown badges for the current package. Generate Markdown badges for the current package.
# Arguments # Arguments
* `plugin::GitHubPages`: plugin whose badges we are generating. * `plugin::GitHubPages`: plugin whose badges we are generating.
* `t::Template`: Template configuration options. * `t::Template`: Template configuration options.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of Markdown badges.
""" """
function badges(plugin::GitHubPages, t::Template, pkg_name::AbstractString) function badges(plugin::GitHubPages, t::Template, pkg_name::AbstractString)
if haskey(t.plugins, TravisCI) if haskey(t.plugins, TravisCI)
@ -57,7 +56,7 @@ GitHub Pages.
* `template::Template`: Template configuration and plugins. * `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of generated directories (["docs"]) for git to add. Returns an array of generated directories.
""" """
function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractString) function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractString)
invoke( invoke(

View File

@ -1,21 +1,25 @@
""" """
TravisCI(;config_file::AbstractString="") -> TravisCI TravisCI(; config_file::AbstractString="") -> TravisCI
Add TravisCI to a template's plugins to enable Travis CI. Add TravisCI to a template's plugins to add Travis CI support.
# Keyword Arguments: # Keyword Arguments:
* `config_file::AbstractString`: Path to a custom `.travis.yml`. * `config_file::AbstractString`: Path to a custom `.travis.yml`.
If `nothing` is supplied, then no file will be generated.
""" """
struct TravisCI <: Plugin struct TravisCI <: Plugin
gitignore_files::Vector{AbstractString} gitignore_files::Vector{AbstractString}
config_file::AbstractString config_file::Union{AbstractString, Void}
function TravisCI(;config_file::AbstractString="") function TravisCI(; config_file::Union{AbstractString, Void}="")
config_file = isempty(config_file) ? if config_file != nothing
joinpath(DEFAULTS_DIR, "travis.yml") : config_file if isempty(config_file)
if !isfile(config_file) config_file = joinpath(DEFAULTS_DIR, "travis.yml")
end
if !isfile(abspath(config_file))
throw(ArgumentError("File $config_file does not exist")) throw(ArgumentError("File $config_file does not exist"))
end end
end
new(AbstractString[], config_file) new(AbstractString[], config_file)
end end
end end
@ -26,14 +30,16 @@ function ==(a::TravisCI, b::TravisCI)
end end
""" """
badges(plugin::TravisCI, pkg_name::AbstractString, t::Template) -> String badges(plugin::TravisCI, pkg_name::AbstractString, t::Template) -> Vector{String}
Return Markdown badges for the current package. Generate Markdown badges for the current package.
# Arguments # Arguments
* `plugin::TravisCI`: plugin whose badges we are generating. * `plugin::TravisCI`: plugin whose badges we are generating.
* `t::Template`: Template configuration and plugins. * `t::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of Markdown badges.
""" """
function badges(plugin::TravisCI, t::Template, pkg_name::AbstractString) function badges(plugin::TravisCI, t::Template, pkg_name::AbstractString)
user = strip(URI(t.remote_prefix).path, '/') user = strip(URI(t.remote_prefix).path, '/')
@ -43,7 +49,7 @@ function badges(plugin::TravisCI, t::Template, pkg_name::AbstractString)
end end
""" """
gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString) gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString) -> Vector{String}
Generate a .travis.yml. Generate a .travis.yml.
@ -52,9 +58,12 @@ Generate a .travis.yml.
* `template::Template`: Template configuration and plugins. * `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package. * `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files ([".travis.yml"]) for git to add. Returns an array of generated files.
""" """
function gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString) function gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
text = substitute(readstring(plugin.config_file), pkg_name, template) text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name) pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".travis.yml"), text) gen_file(joinpath(pkg_dir, ".travis.yml"), text)