Use Pkg.devdir instead of our own implementation (close #28)
This commit is contained in:
parent
07e2277a17
commit
78a4fb0b9b
@ -1,16 +1,15 @@
|
||||
"""
|
||||
generate(pkg_name::AbstractString, t::Template) -> Nothing
|
||||
generate(pkg::AbstractString, t::Template) -> Nothing
|
||||
generate(t::Template, pkg::AbstractString) -> Nothing
|
||||
|
||||
Generate a package named `pkg_name` from `t`.
|
||||
Generate a package named `pkg` from `t`.
|
||||
"""
|
||||
function generate(pkg_name::AbstractString, t::Template)
|
||||
pkg_dir = joinpath(t.dir, pkg_name)
|
||||
function generate(pkg::AbstractString, t::Template)
|
||||
pkg = splitjl(pkg)
|
||||
pkg_dir = joinpath(t.dir, pkg)
|
||||
ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists"))
|
||||
|
||||
try
|
||||
pkg_name = splitjl(pkg_name)
|
||||
pkg_dir = joinpath(t.dir, pkg_name)
|
||||
|
||||
# Create the directory with some boilerplate inside.
|
||||
Pkg.generate(pkg_dir)
|
||||
|
||||
@ -19,9 +18,9 @@ function generate(pkg_name::AbstractString, t::Template)
|
||||
@info "Initialized git repo at $pkg_dir"
|
||||
LibGit2.commit(repo, "Initial commit")
|
||||
rmt = if t.ssh
|
||||
"git@$(t.host):$(t.user)/$pkg_name.jl.git"
|
||||
"git@$(t.host):$(t.user)/$pkg.jl.git"
|
||||
else
|
||||
"https://$(t.host)/$(t.user)/$pkg_name.jl"
|
||||
"https://$(t.host)/$(t.user)/$pkg.jl"
|
||||
end
|
||||
# We need to set the remote in a strange way, see #8.
|
||||
close(LibGit2.GitRemote(repo, "origin", rmt))
|
||||
@ -43,7 +42,7 @@ function generate(pkg_name::AbstractString, t::Template)
|
||||
gen_readme(pkg_dir, t),
|
||||
gen_gitignore(pkg_dir, t),
|
||||
gen_license(pkg_dir, t),
|
||||
vcat(map(p -> gen_plugin(p, t, pkg_name), values(t.plugins))...),
|
||||
vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...),
|
||||
)
|
||||
|
||||
LibGit2.add!(repo, files...)
|
||||
@ -60,7 +59,7 @@ function generate(pkg_name::AbstractString, t::Template)
|
||||
end
|
||||
end
|
||||
|
||||
generate(t::Template, pkg_name::AbstractString) = generate(pkg_name, t)
|
||||
generate(t::Template, pkg::AbstractString) = generate(pkg, t)
|
||||
|
||||
"""
|
||||
generate_interactive(pkg::AbstractString; fast::Bool=false) -> Template
|
||||
|
@ -1,10 +1,3 @@
|
||||
"""
|
||||
dev_dir() -> String
|
||||
|
||||
Get the default development directory (~/.julia/dev).
|
||||
"""
|
||||
dev_dir() = joinpath(first(DEPOT_PATH), "dev")
|
||||
|
||||
"""
|
||||
Template(; kwargs...) -> Template
|
||||
|
||||
@ -13,9 +6,9 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
|
||||
# Keyword Arguments
|
||||
* `user::AbstractString=""`: GitHub (or other code hosting service) username. If left
|
||||
unset, it will take the the global git config's value. If that is not set, an
|
||||
`ArgumentError` is thrown. **This is case-sensitive for some plugins, so take care to
|
||||
enter it correctly.**
|
||||
unset, it will take the the global git config's value (`github.user`). If that is not
|
||||
set, an `ArgumentError` is thrown. **This is case-sensitive for some plugins, so take
|
||||
care to enter it correctly.**
|
||||
* `host::AbstractString="github.com"`: URL to the code hosting service where your package
|
||||
will reside. Note that while hosts other than GitHub won't cause errors, they are not
|
||||
officially supported and they will cause certain plugins will produce incorrect output.
|
||||
@ -26,9 +19,9 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
* `authors::Union{AbstractString, Vector{<:AbstractString}}=""`: Names that appear on the
|
||||
license. Supply a string for one author or an array for multiple. Similarly to `user`,
|
||||
it will take the value of of the global git config's value if it is left unset.
|
||||
* `dir::AbstractString=$(dev_dir())`: Directory in which the package will go. Relative
|
||||
paths are converted to absolute ones at template creation time.
|
||||
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
|
||||
* `dir::AbstractString=$(replace(Pkg.devdir(), homedir() => "~"))`: Directory in which the
|
||||
package will go. Relative paths are converted to absolute ones at template creation time.
|
||||
* `julia_version::VersionNumber=$VERSION`: Minimum allowed Julia version.
|
||||
* `ssh::Bool=false`: Whether or not to use SSH for the remote.
|
||||
* `plugins::Vector{<:Plugin}=Plugin[]`: A list of `Plugin`s that the package will include.
|
||||
"""
|
||||
@ -47,7 +40,7 @@ create a template, you can use [`interactive_template`](@ref) instead.
|
||||
host::AbstractString="https://github.com",
|
||||
license::AbstractString="MIT",
|
||||
authors::Union{AbstractString, Vector{<:AbstractString}}="",
|
||||
dir::AbstractString=dev_dir(),
|
||||
dir::AbstractString=Pkg.devdir(),
|
||||
julia_version::VersionNumber=VERSION,
|
||||
ssh::Bool=false,
|
||||
plugins::Vector{<:Plugin}=Plugin[],
|
||||
@ -186,9 +179,9 @@ function interactive_template(; fast::Bool=false)
|
||||
end
|
||||
|
||||
kwargs[:dir] = if fast
|
||||
dev_dir()
|
||||
Pkg.devdir()
|
||||
else
|
||||
default_dir = dev_dir()
|
||||
default_dir = Pkg.devdir()
|
||||
print("Enter the path to the package directory [$default_dir]: ")
|
||||
dir = readline()
|
||||
isempty(dir) ? default_dir : dir
|
||||
|
@ -2,6 +2,7 @@ using PkgTemplates
|
||||
using Test
|
||||
using Dates
|
||||
using LibGit2
|
||||
using Pkg
|
||||
|
||||
import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme,
|
||||
gen_tests, gen_license, gen_require, gen_gitignore, gen_plugin, show_license, LICENSES,
|
||||
|
@ -19,7 +19,7 @@ const me = "christopher-dG"
|
||||
const test_pkg = "TestPkg"
|
||||
const fake_path = "/dev/null/this/file/does/not/exist"
|
||||
const test_file = tempname()
|
||||
const default_dir = PkgTemplates.dev_dir()
|
||||
const default_dir = Pkg.devdir()
|
||||
const template_text = """
|
||||
PKGNAME: {{PKGNAME}}
|
||||
VERSION: {{VERSION}}}
|
||||
|
Loading…
Reference in New Issue
Block a user