PkgTemplates
PkgTemplates is a Julia package for creating new Julia packages in an easy, repeatable, and customizable way.
Installation
PkgTemplates
is registered in METADATA.jl
, so run Pkg.add("PkgTemplates")
for the latest release, or Pkg.clone("PkgTemplates")
for the development version.
Usage
The simplest template only requires your GitHub username.
julia> using PkgTemplates
julia> t = Template(; user="myusername")
PkgTemplates.Template("myusername", "github.com", "MIT", "Travis CI User", "2017", "/home/travis/.julia/v0.6", v"0.6.0", AbstractString[], Dict{Any,Any}(), Dict{DataType,PkgTemplates.Plugin}())
julia> generate("MyPkg", t)
INFO: Initialized git repo at /tmp/tmpxDMyLD/MyPkg
INFO: Made initial empty commit
INFO: Set remote origin to https://github.com/myusername/MyPkg.jl
INFO: Staged 6 files/directories: src/, test/, REQUIRE, README.md, .gitignore, LICENSE
INFO: Committed files generated by PkgTemplates
INFO: Moving temporary package directory into /home/travis/.julia/v0.6/
INFO: Finished
julia> cd(joinpath(t.dir, "MyPkg")); run(`git ls-tree -r --name-only HEAD`)
.gitignore
LICENSE
README.md
REQUIRE
src/MyPkg.jl
test/runtests.jl
However, we can also configure a number of keyword arguments to Template
and generate
:
julia> using PkgTemplates
julia> t = Template(;
user="myusername",
license="MIT",
authors=["Chris de Graaf", "Invenia Technical Computing Corporation"],
years="2016-2017",
dir=joinpath(homedir(), "code"),
julia_version=v"0.5.2",
requirements=["PkgTemplates"],
gitconfig=Dict("diff.renames" => true),
plugins=[
TravisCI(),
CodeCov(; config_file=nothing),
Coveralls(),
AppVeyor(),
GitHubPages(),
],
)
PkgTemplates.Template("myusername", "github.com", "MIT", "Chris de Graaf, Invenia Technical Computing Corporation", "2016-2017", "/home/travis/code", v"0.5.2", AbstractString["PkgTemplates"], Dict("diff.renames"=>true), Dict{DataType,PkgTemplates.Plugin}(Pair{DataType,PkgTemplates.Plugin}(PkgTemplates.TravisCI, PkgTemplates.TravisCI(AbstractString[], "/home/travis/.julia/v0.6/PkgTemplates/defaults/travis.yml", ".travis.yml", PkgTemplates.Badge[PkgTemplates.Badge("Build Status", "https://travis-ci.org/{{USER}}/{{PKGNAME}}.jl.svg?branch=master", "https://travis-ci.org/{{USER}}/{{PKGNAME}}.jl")], Dict{String,Any}())),Pair{DataType,PkgTemplates.Plugin}(PkgTemplates.AppVeyor, PkgTemplates.AppVeyor(AbstractString[], "/home/travis/.julia/v0.6/PkgTemplates/defaults/appveyor.yml", ".appveyor.yml", PkgTemplates.Badge[PkgTemplates.Badge("Build Status", "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKGNAME}}.jl?svg=true", "https://ci.appveyor.com/project/{{USER}}/{{PKGNAME}}-jl")], Dict{String,Any}())),Pair{DataType,PkgTemplates.Plugin}(PkgTemplates.GitHubPages, PkgTemplates.GitHubPages(AbstractString["/docs/build/", "/docs/site/"], AbstractString[])),Pair{DataType,PkgTemplates.Plugin}(PkgTemplates.CodeCov, PkgTemplates.CodeCov(AbstractString["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], #NULL, ".codecov.yml", PkgTemplates.Badge[PkgTemplates.Badge("CodeCov", "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl/branch/master/graph/badge.svg", "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl")], Dict{String,Any}())),Pair{DataType,PkgTemplates.Plugin}(PkgTemplates.Coveralls, PkgTemplates.Coveralls(AbstractString["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], #NULL, ".coveralls.yml", PkgTemplates.Badge[PkgTemplates.Badge("Coveralls", "https://coveralls.io/repos/github/{{USER}}/{{PKGNAME}}.jl/badge.svg?branch=master", "https://coveralls.io/github/{{USER}}/{{PKGNAME}}.jl?branch=master")], Dict{String,Any}()))))
julia> generate("MyPkg", t; force=true, ssh=true)
INFO: Initialized git repo at /tmp/tmpA25O86/MyPkg
INFO: Applying git configuration
INFO: Made initial empty commit
INFO: Set remote origin to git@github.com:myusername/MyPkg.jl.git
INFO: Created empty gh-pages branch
INFO: Staged 9 files/directories: src/, test/, REQUIRE, README.md, .gitignore, LICENSE, .travis.yml, .appveyor.yml, docs/
INFO: Committed files generated by PkgTemplates
INFO: Moving temporary package directory into /home/travis/code/
INFO: Finished
WARNING: Remember to push all created branches to your remote: git push --all
julia> cd(joinpath(t.dir, "MyPkg")); run(`git ls-tree -r --name-only HEAD`)
.appveyor.yml
.gitignore
.travis.yml
LICENSE
README.md
REQUIRE
docs/make.jl
docs/src/index.md
src/MyPkg.jl
test/runtests.jl
If that looks like a lot of work, you can also create templates interactively with interactive_template
:
And if that's still too much work for you, you can call interactive_template
with fast=true
to use default values for everything but username and plugin selection.
You can also use generate_interactive
to interactively generate a template and then immediately use it to create a new package.
Comparison to PkgDev
PkgTemplates
is similar in functionality to PkgDev
's generate
function. However, PkgTemplates
offers more customizability in templates and more extensibility via plugins. For the package registration and release management features that PkgTemplates
lacks, you are encouraged to use AttoBot instead.