A CLI tool to keep track of templates and generate files from them.
For a more detailed documentation visit the templify-docs.
Working on a project often requires the creation of files with a similar structure. For example, a React component often consists of a .tsx
file, a .scss
file and a .test.tsx
file. templify allows you to create templates for such files and generate them from the command line.
It also allows you to specify the location of the generated files to keep your project structure clean.
You can see a real world example here.
Run the following command in your terminal to isntall the latest version of templify:
curl -s https://raw.githubusercontent.com/cophilot/templify/master/install | bash -s -- -y
Optionally you can specify a version with the -v
flag:
curl -s https://raw.githubusercontent.com/cophilot/templify/master/install | bash -s -- -y -v <version>
You can also define the installation path with the -p
flag:
curl -s https://raw.githubusercontent.com/cophilot/templify/master/install | bash -s -- -y -p /usr/local/bin
or download the binary from the latest release and place it in your $PATH
.
You may need to restart your terminal after installation for the changes to take effect.
After installation run
tpy version
to verify that the installation was successful.
tpy.exe
binary from the latest releaseC:\Program Files\templify
bin
tpy.exe
binary inside the bin
folderbin
folder to your system's PATH variableAfter installation run
tpy version
to verify that the installation was successful.
You can run an docker container with an installed templify version to try out the features. Just run the following commands:
git clone https://github.com/cophilot/templify.git
cd templify
docker build . --tag templify-image
docker run -it templify-image bash
You can either run the CLI tool directly on your machine or use the dev-container.
./scripts/setup
cargo run <arguments> --dev
to run the CLI toolTODO
The CI pipeline ensures the quality of the code. It runs the following checks:
You can find the pipeline configuration in the .github/workflows/check_rust_quality.yml file.
A template is a folder in the .templates
directory of your project. It contains all files and subfolders that should be generated when the template is used. You can use placeholders to replace parts of the template with the given values.
Each template must contain a .templify
file that specifies some metadata about the template.
The .templify
file contains metadata about the template. It is a key-value file with the following keys:
description
: A short description of the templatepath
: The path where the generated files should be placed based on the root of the project. This can also be a path with placeholders in it.tpy [command]
Commands:
tpy help
Displays help for templify.
tpy version
Displays the current version of templify.
tpy init
Initializes templify in the current directory.
tpy new <template-name>
Creates a new template with the given name.
tpy load <url>
Load predefined templates from a GitHub repository into your project. The url should point to a folder inside a GitHub repository. Each folder inside there will be imported as a template in your .templates. See the templify-vault for more informations.
tpy list
Lists all available templates in the current project.
tpy generate <template-name> <given-name>
Generates a file from the given template.
$$name$$
: The name of the new file (This placeholder supports case conversion).$$year$$
: The current year.$$month$$
: The current month as a number.$$month-name$$
: The current month as a name.$$day$$
: The current day.$$git-name$$
: The name of the git user.Case conversion is used to convert placeholders to different case styles. You can use them by adding a .
and the case style to a placeholder that supports case conversion.
Example: $$name.kebab$$
You can use the following case conversion:
$$<placeholder>.lower$$
: Lower case (e.g. mycomponent
)$$<placeholder>.upper$$
: Upper case (e.g. MYCOMPONENT
)$$<placeholder>.camel$$
: Camel case (e.g. myComponent
)$$<placeholder>.snake$$
: Snake case (e.g. my_component
)$$<placeholder>.kebab$$
: Kebab case (e.g. my-component
)$$<placeholder>.pascal$$
: Pascal case (e.g. MyComponent
)$$<placeholder>.macro$$
: Macro case (e.g. MY_COMPONENT
)$$<placeholder>.train$$
: Train case (e.g. My-Component
)The templify-vault repository contains some default templates that you can import with the load
command.
Example:
You wanna start a new React project with typescript? Just run this command to import templates for default components for you React app:
tpy load https://github.com/cophilot/templify-vault/tree/main/React-ts
-reset
flag for the reload
command-force
flag for the generate
command-reload
flag for the generate
command-var
flag for the generate
command-default-var
flag for the generate
command.templify
file--quiet
global flag--dev
global flag--log-file
global flagby Philipp B.