diff --git a/Project.toml b/Project.toml index c7991a0..cc00980 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.1.0" AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" +LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" TerminalMenus = "dc548174-15c3-5faf-af27-7997cfbde655" URIParser = "30578b45-9adc-5946-b283-645ec420af67" diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index f07b6ce..5d6437f 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -8,6 +8,8 @@ using Mustache using TerminalMenus using URIParser +import LibGit2 + export # Template/package generation. Template, diff --git a/src/generate.jl b/src/generate.jl index 80e13e3..5eb0362 100644 --- a/src/generate.jl +++ b/src/generate.jl @@ -42,7 +42,7 @@ function generate( ssh::Bool=false, backup_dir::AbstractString="", ) - pkg_name = Pkg.splitjl(pkg_name) + pkg_name = splitjl(pkg_name) pkg_dir = joinpath(t.dir, pkg_name) temp_pkg_dir = joinpath(dir, pkg_name) @@ -54,15 +54,15 @@ function generate( # Initialize the repo and configure it. 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 for (key, val) in t.gitconfig LibGit2.set!(cfg, key, val) end end - !isempty(t.gitconfig) && info("Applied git configuration") + !isempty(t.gitconfig) && @info "Applied git configuration" LibGit2.commit(repo, "Initial commit") - info("Made empty initial commit") + @info "Made empty initial commit" rmt = if ssh "git@$(t.host):$(t.user)/$pkg_name.jl.git" else @@ -70,13 +70,13 @@ function generate( end # We need to set the remote in a strange way, see #8. 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. if haskey(t.plugins, GitHubPages) LibGit2.branch!(repo, "gh-pages") LibGit2.commit(repo, "Empty initial commit") - info("Created empty gh-pages branch") + @info "Created empty gh-pages branch" LibGit2.branch!(repo, "master") end @@ -92,14 +92,14 @@ function generate( ) 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") - info("Committed files generated by PkgTemplates") + @info "Committed files generated by PkgTemplates" multiple_branches = length(collect(LibGit2.GitBranchIter(repo))) > 1 try mkpath(dirname(pkg_dir)) - mv(temp_pkg_dir, pkg_dir; remove_destination=force) - info("Moved temporary package directory into $(t.dir)/") + mv(temp_pkg_dir, pkg_dir; force=force) + @info "Moved temporary package directory into $(t.dir)/" 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. 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") end - info("Finished") + @info "Finished" if multiple_branches warn("Remember to push all created branches to your remote: git push --all") end @@ -426,3 +426,10 @@ function substitute( d["AFTER"] = d["DOCUMENTER"] || d["CODECOV"] || d["COVERALLS"] return substitute(template, merge(d, view)) 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 diff --git a/src/plugin.jl b/src/plugin.jl index 13d2129..02e1a17 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -71,12 +71,12 @@ abstract type GenericPlugin <: Plugin end function show(io::IO, p::GenericPlugin) spc = " " - println(io, "$(Base.datatype_name(typeof(p))):") + println(io, "$(nameof(typeof(p))):") - cfg = if isnull(p.src) + cfg = if p.src === nothing "None" else - dirname(get(p.src)) == DEFAULTS_DIR ? "Default" : get(p.src) + dirname(p.src) == DEFAULTS_DIR ? "Default" : p.src end println(io, "$spc→ Config file: $cfg") @@ -214,7 +214,7 @@ function gen_plugin( pkg_name::AbstractString, ) src = try - get(plugin.src) + plugin.src catch return String[] end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index b699146..d01d3f1 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -57,13 +57,13 @@ function gen_plugin( end readme_path = joinpath(dir, pkg_name, "README.md") 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 function show(io::IO, p::Documenter) spc = " " - println(io, "$(Base.datatype_name(typeof(p))):") + println(io, "$(nameof(typeof(p))):") n = length(p.assets) s = n == 1 ? "" : "s" diff --git a/src/template.jl b/src/template.jl index 3942435..b88024b 100644 --- a/src/template.jl +++ b/src/template.jl @@ -26,8 +26,8 @@ create a template, you can use [`interactive_template`](@ref) instead. 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. Relative paths - are converted to absolute ones at template creation time. +* `dir::AbstractString=joinpath(first(DEPOT_PATH), "dev")`: Directory in which the package + 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. * `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version. * `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", authors::Union{AbstractString, Vector{<:AbstractString}}="", years::Union{Integer, AbstractString}=Dates.year(Dates.today()), - dir::AbstractString=Pkg.dir(), + dir::AbstractString=joinpath(first(DEPOT_PATH), "dev"), precompile::Bool=true, julia_version::VersionNumber=VERSION, requirements::Vector{<:AbstractString}=String[], @@ -128,7 +128,7 @@ function show(io::IO, t::Template) println(io, "$(t.license) ($(t.authors) $(t.years))") 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→ 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. """ 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 # "Select plugins" is printed. plugin_types = @spawn leaves(Plugin) @@ -235,9 +235,9 @@ function interactive_template(; fast::Bool=false) end kwargs[:dir] = if fast - Pkg.dir() + joinpath(first(DEPOT_PATH), "dev") else - default_dir = Pkg.dir() + default_dir = "." print("Enter the path to the package directory [$default_dir]: ") dir = readline() isempty(dir) ? default_dir : dir