diff --git a/src/plugin.jl b/src/plugin.jl index c584649..1654324 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -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} diff --git a/src/plugins/git.jl b/src/plugins/git.jl index 92c5811..d9d93e8 100644 --- a/src/plugins/git.jl +++ b/src/plugins/git.jl @@ -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) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl index ab310d3..91714c0 100644 --- a/src/plugins/project_file.jl +++ b/src/plugins/project_file.jl @@ -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( diff --git a/src/template.jl b/src/template.jl index f88bd6b..84e9ee1 100644 --- a/src/template.jl +++ b/src/template.jl @@ -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