Skip to main content

template.yml

v0.14

The template.yml file configures metadata and variables for a template, used by the generator, and must exist at the root of a named template folder.

template.yml
$schema: 'https://moonrepo.dev/schemas/template.json'

titleRequired

A human readable title that will be displayed during the moon generate process.

template.yml
title: 'npm package'

descriptionRequired

A description of why the template exists, what its purpose is, and any other relevant information.

template.yml
description: |
Scaffolds the initial structure for an npm package,
including source and test folders, a package.json, and more.

variables

A mapping of variables that will be interpolated into all template files and file system paths when rendering with Tera. The map key is the variable name (in camelCase or snake_case), while the value is a configuration object, as described with the settings below.

template.yml
variables:
name:
type: 'string'
default: ''
required: true
prompt: 'Package name?'

defaultRequired

The default value of the variable. When --defaults is passed to moon generate or prompt is not defined, the default value will be used, otherwise the user will be prompted to enter a custom value.

promptRequired for enums

When defined, will prompt the user with a message in the terminal to input a custom value, otherwise default will be used.

typeRequired

The type of value for the variable. Accepts boolean, string, number, or enum. Floats are not supported, use strings instead.

Numbers & strings

Your basic primitives.

required

Marks the variable as required during prompting only. For strings, will error for empty values (''). For numbers, will error for zero's (0).

template.yml
variables:
age:
type: 'number'
default: 0
required: true
prompt: 'Age?'

Enums

An enum is an explicit list of string values that a user can choose from.

template.yml
variables:
color:
type: 'enum'
values: ['red', 'green', 'blue', 'purple']
default: 'purple'
prompt: 'Favorite color?'

multiple

Allows multiple values to be chosen during prompting. In the template, an array or strings will be rendered, otherwise when not-multiple, a single string will be.

valuesRequiredv0.17

List of explicit values to choose from. Can either be defined with a string, which acts as a value and label, or as an object, which defines an explicit value and label.

template.yml
variables:
color:
type: 'enum'
values:
- 'red'
# OR
- value: 'red'
label: 'Red 🔴'
# ...

Frontmatterv0.15

The following settings are not available in template.yml, but can be defined as frontmatter at the top of a template file. View the code generation guide for more information.

force

When enabled, will always overwrite a file of the same name at the destination path, and will bypass any prompting in the terminal.

---
force: true
---

Some template content!

to

Defines a custom file path, relative from the destination root, in which to create the file. This will override the file path within the template folder, and allow for conditional rendering and engine filters to be used.

{% set component_name = name | pascal_case %}

---
to: components/{{ component_name }}.tsx
---

export function {{ component_name }}() {
return <div />;
}

skip

When enabled, the template file will be skipped while writing to the destination path. This setting can be used to conditionally render a file.

---
skip: {{ name == "someCondition" }}
---

Some template content!