This guide explains how to create, structure, and organize custom templates for use with @zysam/use-template.
@zysam/use-template automatically discovers templates in the following order:
- Built-in Package Templates: Found in the
@zysam/use-templatepackage directory (templates/). - User Global Templates: Located at
~/.use-template/templates. - Local Project Templates: Located in
./templatesrelative to your current execution directory. - Environment Variable: Paths defined in
USE_TEMPLATE_DIR(separated by:or;). - Command Option: Directories added dynamically via
use-template create -t <path>.
A template is simply a folder containing starter files for a project.
my-templates/
└── my-awesome-template/
├── .gitignore
├── package.json
├── README.md
├── tsconfig.json
└── src/
└── index.ts
If your template contains a package.json with a description field, @zysam/use-template will automatically read and display it in use-template list and interactive selection menus.
Example package.json:
{
"name": "my-awesome-template",
"version": "1.0.0",
"description": "Opinionated TypeScript CLI project template with Vitest and ESLint"
}By default, @zysam/use-template ignores build artifacts and dependencies (node_modules/**, dist/**, .git/**).
If your template directory contains a .gitignore file, @zysam/use-template will parse its rules and convert them to glob patterns. Any matching files in the template directory will not be copied to the new project.
When a user creates a new project using use-template create:
package.jsonname: The"name"field in the target project'spackage.jsonis updated to the user's chosen project name.README.md: Occurrences of the template name inREADME.mdare replaced with the new project name.isReplaceAlloption: IfisReplaceAllis enabled (prompted interactively or set in code), all text files matching common extensions (.ts,.tsx,.js,.jsx,.json,.md,.yml,.yaml,.html) will have occurrences of the original template name automatically replaced with the new project name.
- Create a directory in your home folder:
mkdir -p ~/.use-template/templates/express-api - Add project starter files (e.g.,
package.json,src/index.js,.gitignore). - Set the
descriptioninpackage.json:{ "name": "express-api", "description": "Minimal Express REST API starter" } - Test your template:
use-template list
- Create a project:
use-template create