Enable priority per-hook
This commit is contained in:
parent
5e843dadbb
commit
6d95bf78a0
@ -61,12 +61,14 @@ By default, the tags are `"{{"` and `"}}"`.
|
||||
tags(::Plugin) = "{{", "}}"
|
||||
|
||||
"""
|
||||
priority(::Plugin) -> Int
|
||||
priority(::Plugin, ::Union{typeof(prehook), typeof(hook), typeof(posthook)}) -> Int
|
||||
|
||||
Determines the order in which plugins are processed (higher goes first).
|
||||
The default priority (`DEFAULT_PRIORITY`), is `$DEFAULT_PRIORITY`.
|
||||
|
||||
You can implement this function per-stage (by using `::typeof(hook)`, for example), or for all stages by simply using `::Function`.
|
||||
"""
|
||||
priority(::Plugin) = DEFAULT_PRIORITY
|
||||
priority(::Plugin, ::Function) = DEFAULT_PRIORITY
|
||||
|
||||
"""
|
||||
gitignore(::Plugin) -> Vector{String}
|
||||
|
@ -19,6 +19,9 @@ Creates a Git repository and a `.gitignore` file.
|
||||
gpgsign::Bool = false
|
||||
end
|
||||
|
||||
# Try to make sure that no files are created after we commit.
|
||||
priority(::Git, ::typeof(posthook)) = 5
|
||||
|
||||
Base.:(==)(a::Git, b::Git) = all(map(n -> getfield(a, n) == getfield(b, n), fieldnames(Git)))
|
||||
|
||||
function gitignore(p::Git)
|
||||
|
@ -6,7 +6,7 @@ Creates a `Project.toml`.
|
||||
struct ProjectFile <: Plugin end
|
||||
|
||||
# Other plugins like Tests will modify this file.
|
||||
priority(::ProjectFile) = typemax(Int) - DEFAULT_PRIORITY + 1
|
||||
priority(::ProjectFile, ::typeof(hook)) = typemax(Int) - 5
|
||||
|
||||
function hook(::ProjectFile, t::Template, pkg_dir::AbstractString)
|
||||
toml = Dict(
|
||||
|
@ -77,8 +77,7 @@ function Template(::Val{false}; kwargs...)
|
||||
append!(plugins, getkw(kwargs, :plugins))
|
||||
disabled = getkw(kwargs, :disable_defaults)
|
||||
append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins()))
|
||||
plugins = unique(typeof, plugins)
|
||||
sort!(plugins; by=priority, rev=true)
|
||||
plugins = sort(unique(typeof, plugins); by=string)
|
||||
|
||||
return Template(authors, dir, host, julia_version, plugins, user)
|
||||
end
|
||||
@ -97,7 +96,7 @@ function (t::Template)(pkg::AbstractString)
|
||||
try
|
||||
foreach((prehook, hook, posthook)) do h
|
||||
@info "Running $(nameof(h))s"
|
||||
foreach(t.plugins) do p
|
||||
foreach(sort(t.plugins; by=p -> priority(p, h), rev=true)) do p
|
||||
h(p, t, pkg_dir)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user