More deprecations: info, Pkg, nullables, and more, and update default pkg dir
This commit is contained in:
parent
a87e6a0807
commit
adbbfd887d
@ -7,6 +7,7 @@ version = "0.1.0"
|
|||||||
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
|
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
|
||||||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
|
||||||
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
|
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
|
||||||
|
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
|
||||||
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70"
|
||||||
TerminalMenus = "dc548174-15c3-5faf-af27-7997cfbde655"
|
TerminalMenus = "dc548174-15c3-5faf-af27-7997cfbde655"
|
||||||
URIParser = "30578b45-9adc-5946-b283-645ec420af67"
|
URIParser = "30578b45-9adc-5946-b283-645ec420af67"
|
||||||
|
@ -8,6 +8,8 @@ using Mustache
|
|||||||
using TerminalMenus
|
using TerminalMenus
|
||||||
using URIParser
|
using URIParser
|
||||||
|
|
||||||
|
import LibGit2
|
||||||
|
|
||||||
export
|
export
|
||||||
# Template/package generation.
|
# Template/package generation.
|
||||||
Template,
|
Template,
|
||||||
|
@ -42,7 +42,7 @@ function generate(
|
|||||||
ssh::Bool=false,
|
ssh::Bool=false,
|
||||||
backup_dir::AbstractString="",
|
backup_dir::AbstractString="",
|
||||||
)
|
)
|
||||||
pkg_name = Pkg.splitjl(pkg_name)
|
pkg_name = splitjl(pkg_name)
|
||||||
pkg_dir = joinpath(t.dir, pkg_name)
|
pkg_dir = joinpath(t.dir, pkg_name)
|
||||||
temp_pkg_dir = joinpath(dir, pkg_name)
|
temp_pkg_dir = joinpath(dir, pkg_name)
|
||||||
|
|
||||||
@ -54,15 +54,15 @@ function generate(
|
|||||||
|
|
||||||
# Initialize the repo and configure it.
|
# Initialize the repo and configure it.
|
||||||
repo = LibGit2.init(temp_pkg_dir)
|
repo = LibGit2.init(temp_pkg_dir)
|
||||||
info("Initialized git repo at $temp_pkg_dir")
|
@info "Initialized git repo at $temp_pkg_dir"
|
||||||
LibGit2.with(LibGit2.GitConfig, repo) do cfg
|
LibGit2.with(LibGit2.GitConfig, repo) do cfg
|
||||||
for (key, val) in t.gitconfig
|
for (key, val) in t.gitconfig
|
||||||
LibGit2.set!(cfg, key, val)
|
LibGit2.set!(cfg, key, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
!isempty(t.gitconfig) && info("Applied git configuration")
|
!isempty(t.gitconfig) && @info "Applied git configuration"
|
||||||
LibGit2.commit(repo, "Initial commit")
|
LibGit2.commit(repo, "Initial commit")
|
||||||
info("Made empty initial commit")
|
@info "Made empty initial commit"
|
||||||
rmt = if ssh
|
rmt = if ssh
|
||||||
"git@$(t.host):$(t.user)/$pkg_name.jl.git"
|
"git@$(t.host):$(t.user)/$pkg_name.jl.git"
|
||||||
else
|
else
|
||||||
@ -70,13 +70,13 @@ function generate(
|
|||||||
end
|
end
|
||||||
# We need to set the remote in a strange way, see #8.
|
# We need to set the remote in a strange way, see #8.
|
||||||
close(LibGit2.GitRemote(repo, "origin", rmt))
|
close(LibGit2.GitRemote(repo, "origin", rmt))
|
||||||
info("Set remote origin to $rmt")
|
@info "Set remote origin to $rmt"
|
||||||
|
|
||||||
# Create the gh-pages branch if necessary.
|
# Create the gh-pages branch if necessary.
|
||||||
if haskey(t.plugins, GitHubPages)
|
if haskey(t.plugins, GitHubPages)
|
||||||
LibGit2.branch!(repo, "gh-pages")
|
LibGit2.branch!(repo, "gh-pages")
|
||||||
LibGit2.commit(repo, "Empty initial commit")
|
LibGit2.commit(repo, "Empty initial commit")
|
||||||
info("Created empty gh-pages branch")
|
@info "Created empty gh-pages branch"
|
||||||
LibGit2.branch!(repo, "master")
|
LibGit2.branch!(repo, "master")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -92,14 +92,14 @@ function generate(
|
|||||||
)
|
)
|
||||||
|
|
||||||
LibGit2.add!(repo, files...)
|
LibGit2.add!(repo, files...)
|
||||||
info("Staged $(length(files)) files/directories: $(join(files, ", "))")
|
@info "Staged $(length(files)) files/directories: $(join(files, ", "))"
|
||||||
LibGit2.commit(repo, "Files generated by PkgTemplates")
|
LibGit2.commit(repo, "Files generated by PkgTemplates")
|
||||||
info("Committed files generated by PkgTemplates")
|
@info "Committed files generated by PkgTemplates"
|
||||||
multiple_branches = length(collect(LibGit2.GitBranchIter(repo))) > 1
|
multiple_branches = length(collect(LibGit2.GitBranchIter(repo))) > 1
|
||||||
try
|
try
|
||||||
mkpath(dirname(pkg_dir))
|
mkpath(dirname(pkg_dir))
|
||||||
mv(temp_pkg_dir, pkg_dir; remove_destination=force)
|
mv(temp_pkg_dir, pkg_dir; force=force)
|
||||||
info("Moved temporary package directory into $(t.dir)/")
|
@info "Moved temporary package directory into $(t.dir)/"
|
||||||
catch # Likely cause is that t.dir can't be created (is a file, etc.).
|
catch # Likely cause is that t.dir can't be created (is a file, etc.).
|
||||||
# We're just going to trust that backup_dir is a valid directory.
|
# We're just going to trust that backup_dir is a valid directory.
|
||||||
backup_dir = if isempty(backup_dir)
|
backup_dir = if isempty(backup_dir)
|
||||||
@ -112,7 +112,7 @@ function generate(
|
|||||||
warn("$pkg_name couldn't be moved into $pkg_dir, left package in $backup_dir")
|
warn("$pkg_name couldn't be moved into $pkg_dir, left package in $backup_dir")
|
||||||
end
|
end
|
||||||
|
|
||||||
info("Finished")
|
@info "Finished"
|
||||||
if multiple_branches
|
if multiple_branches
|
||||||
warn("Remember to push all created branches to your remote: git push --all")
|
warn("Remember to push all created branches to your remote: git push --all")
|
||||||
end
|
end
|
||||||
@ -426,3 +426,10 @@ function substitute(
|
|||||||
d["AFTER"] = d["DOCUMENTER"] || d["CODECOV"] || d["COVERALLS"]
|
d["AFTER"] = d["DOCUMENTER"] || d["CODECOV"] || d["COVERALLS"]
|
||||||
return substitute(template, merge(d, view))
|
return substitute(template, merge(d, view))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
splitjl(pkg::AbstractString) -> AbstractString
|
||||||
|
|
||||||
|
Remove ".jl" from the end of a package name if it is present.
|
||||||
|
"""
|
||||||
|
splitjl(pkg::AbstractString) = endswith(pkg, ".jl") ? pkg[1:end-3] : pkg
|
||||||
|
@ -71,12 +71,12 @@ abstract type GenericPlugin <: Plugin end
|
|||||||
|
|
||||||
function show(io::IO, p::GenericPlugin)
|
function show(io::IO, p::GenericPlugin)
|
||||||
spc = " "
|
spc = " "
|
||||||
println(io, "$(Base.datatype_name(typeof(p))):")
|
println(io, "$(nameof(typeof(p))):")
|
||||||
|
|
||||||
cfg = if isnull(p.src)
|
cfg = if p.src === nothing
|
||||||
"None"
|
"None"
|
||||||
else
|
else
|
||||||
dirname(get(p.src)) == DEFAULTS_DIR ? "Default" : get(p.src)
|
dirname(p.src) == DEFAULTS_DIR ? "Default" : p.src
|
||||||
end
|
end
|
||||||
println(io, "$spc→ Config file: $cfg")
|
println(io, "$spc→ Config file: $cfg")
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ function gen_plugin(
|
|||||||
pkg_name::AbstractString,
|
pkg_name::AbstractString,
|
||||||
)
|
)
|
||||||
src = try
|
src = try
|
||||||
get(plugin.src)
|
plugin.src
|
||||||
catch
|
catch
|
||||||
return String[]
|
return String[]
|
||||||
end
|
end
|
||||||
|
@ -57,13 +57,13 @@ function gen_plugin(
|
|||||||
end
|
end
|
||||||
readme_path = joinpath(dir, pkg_name, "README.md")
|
readme_path = joinpath(dir, pkg_name, "README.md")
|
||||||
if isfile(readme_path)
|
if isfile(readme_path)
|
||||||
cp(readme_path, joinpath(docs_dir, "index.md"), remove_destination=true)
|
cp(readme_path, joinpath(docs_dir, "index.md"), force=true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function show(io::IO, p::Documenter)
|
function show(io::IO, p::Documenter)
|
||||||
spc = " "
|
spc = " "
|
||||||
println(io, "$(Base.datatype_name(typeof(p))):")
|
println(io, "$(nameof(typeof(p))):")
|
||||||
|
|
||||||
n = length(p.assets)
|
n = length(p.assets)
|
||||||
s = n == 1 ? "" : "s"
|
s = n == 1 ? "" : "s"
|
||||||
|
@ -26,8 +26,8 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
|||||||
git config's value, if it is left unset.
|
git config's value, if it is left unset.
|
||||||
* `years::Union{Integer, AbstractString}=Dates.year(Dates.today())`: Copyright years on the
|
* `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".
|
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. Relative paths
|
* `dir::AbstractString=joinpath(first(DEPOT_PATH), "dev")`: Directory in which the package
|
||||||
are converted to absolute ones at template creation time.
|
will go. Relative paths are converted to absolute ones at template creation time.
|
||||||
* `precompile::Bool=true`: Whether or not to enable precompilation in generated packages.
|
* `precompile::Bool=true`: Whether or not to enable precompilation in generated packages.
|
||||||
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
||||||
* `requirements::Vector{<:AbstractString}=String[]`: Package requirements. If there are
|
* `requirements::Vector{<:AbstractString}=String[]`: Package requirements. If there are
|
||||||
@ -56,7 +56,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
|||||||
license::Union{AbstractString, Nothing}="MIT",
|
license::Union{AbstractString, Nothing}="MIT",
|
||||||
authors::Union{AbstractString, Vector{<:AbstractString}}="",
|
authors::Union{AbstractString, Vector{<:AbstractString}}="",
|
||||||
years::Union{Integer, AbstractString}=Dates.year(Dates.today()),
|
years::Union{Integer, AbstractString}=Dates.year(Dates.today()),
|
||||||
dir::AbstractString=Pkg.dir(),
|
dir::AbstractString=joinpath(first(DEPOT_PATH), "dev"),
|
||||||
precompile::Bool=true,
|
precompile::Bool=true,
|
||||||
julia_version::VersionNumber=VERSION,
|
julia_version::VersionNumber=VERSION,
|
||||||
requirements::Vector{<:AbstractString}=String[],
|
requirements::Vector{<:AbstractString}=String[],
|
||||||
@ -128,7 +128,7 @@ function show(io::IO, t::Template)
|
|||||||
println(io, "$(t.license) ($(t.authors) $(t.years))")
|
println(io, "$(t.license) ($(t.authors) $(t.years))")
|
||||||
end
|
end
|
||||||
|
|
||||||
println(io, "$spc→ Package directory: $(replace(maybe_none(t.dir), homedir(), "~"))")
|
println(io, "$spc→ Package directory: $(replace(maybe_none(t.dir), homedir() => "~"))")
|
||||||
println(io, "$spc→ Precompilation enabled: $(t.precompile ? "Yes" : "No")")
|
println(io, "$spc→ Precompilation enabled: $(t.precompile ? "Yes" : "No")")
|
||||||
println(io, "$spc→ Minimum Julia version: v$(version_floor(t.julia_version))")
|
println(io, "$spc→ Minimum Julia version: v$(version_floor(t.julia_version))")
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ Interactively create a [`Template`](@ref). If `fast` is set, defaults will be as
|
|||||||
all values except username and plugins.
|
all values except username and plugins.
|
||||||
"""
|
"""
|
||||||
function interactive_template(; fast::Bool=false)
|
function interactive_template(; fast::Bool=false)
|
||||||
info("Default values are shown in [brackets]")
|
@info "Default values are shown in [brackets]"
|
||||||
# Getting the leaf types in a separate thread eliminates an awkward wait after
|
# Getting the leaf types in a separate thread eliminates an awkward wait after
|
||||||
# "Select plugins" is printed.
|
# "Select plugins" is printed.
|
||||||
plugin_types = @spawn leaves(Plugin)
|
plugin_types = @spawn leaves(Plugin)
|
||||||
@ -235,9 +235,9 @@ function interactive_template(; fast::Bool=false)
|
|||||||
end
|
end
|
||||||
|
|
||||||
kwargs[:dir] = if fast
|
kwargs[:dir] = if fast
|
||||||
Pkg.dir()
|
joinpath(first(DEPOT_PATH), "dev")
|
||||||
else
|
else
|
||||||
default_dir = Pkg.dir()
|
default_dir = "."
|
||||||
print("Enter the path to the package directory [$default_dir]: ")
|
print("Enter the path to the package directory [$default_dir]: ")
|
||||||
dir = readline()
|
dir = readline()
|
||||||
isempty(dir) ? default_dir : dir
|
isempty(dir) ? default_dir : dir
|
||||||
|
Loading…
Reference in New Issue
Block a user