Devinit is a command-line utility written in Rust that provides the ability to write templates for files and projects and interactively apply them to make boilerplate less annoying.
See the examples
directory for examples of writing file and project templates.
# Configure a file at path 'licence.txt' with the 'LicenceBlock' template,
# specifying values for the variables 'name' and 'year'.
$ devinit file -p licence.txt "LicenceBlock" -Dname="John Doe" -Dyear="2024"
# Process the template 'EditorConfig' and output the result to stdout.
$ devinit file --dry-run "EditorConfig"
# Create and populate a folder called 'dotnet-project' from the project
# template 'DotNet', specifying the variable 'projectName'.
$ devinit project -p dotnet-project/ "DotNet" -DprojectName="Utils"
Devinit is configured using the devinitrc.yml
file, which can be stored at either ~/.devinit/
or ~/.config/devinit/
. Otherwise, it can be
explicitly specified using the --config
command-line option.
devinitrc.yml
enforces a standard YAML syntax. The following fields are required:
Field | Value |
---|---|
file_templates_loc |
File template directory, relative to the configuration file |
project_templates_loc |
Project template directory, relative to the configuration file |
Any folder in the project_templates_loc
directory containing a templaterc.yml
file will be registered as a project template. This
configuration file is YAML, the same as the devinitrc file, and describes which files to process and where to output them.
Field | Value |
---|---|
files |
Dictionary of output paths (relative to evaluated template output) mapped to inputs, e.g. out.txt: input.txt |
A templating engine is provided to allow your configurations to use a simple format similar to Jinja, courtesy of the Tera project - see their documentation for an overview of the syntax.
In addition to a multitude of built-in functions/filters provided by Tera (see docs here), some extras are also provided by Devinit, and are documented below.
Expand a software licence, where id
is a valid SPDX id.
This function returns an object containing each component of the licence. The returned object is split up into the following elements (accessible by dot or square bracket notation):
name
- the licence nameheader
- the standard licence header*text
- the complete licence body
A lot of licences have places to substitute values, like year and copyright holder - it's recommended to use the provided replace filter to handle these template-side.
*Not all licences support the header component (the MIT licence, for example), and attempting to access it on them will result in an error. In these
cases, use the guaranteed text
field instead.
{% set gpl = licence(id = "GPL-2.0-only") -%}
{{ gpl.name }}
{{ gpl.header }}
{{ gpl.text }} {# A very long string #}
Break up the given string into lines of maximum length len
, without breaking individual words.
{{ gpl.text | wrap(len = 80) }}
- VS Code integration (extension)
- List of installed templates (e.g.
devinit --list-templates
- or should it be per sub-command (file, project)?) - Comment blocks - function to take a multi-line string and append a prefix (e.g.
//
before each line)- Standard options for comment blocks, e.g. 'hashtag', 'slash', 'c89', etc.