cophilot / templify

A CLI tool to keep track of templates and generate files from them.
https://templify.philipp-bonin.com
MIT License
1 stars 1 forks source link
cli cli-tool project-management rust template tool

templifyLogo

templify

A CLI tool to keep track of templates and generate files from them.

current realease CI-Pipeline license last commit docs stars

For a more detailed documentation visit the templify-docs.



Concept

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.


Installation

Linux / macOS

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.

Windows

  1. Download the tpy.exe binary from the latest release
  2. Create a root folder for templify, e.g. C:\Program Files\templify
  3. Inside the root folder create a folder called bin
  4. Place the tpy.exe binary inside the bin folder
  5. Add the bin folder to your system's PATH variable

After installation run tpy version to verify that the installation was successful.


Docker

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

Development

Installation

You can either run the CLI tool directly on your machine or use the dev-container.

Local

  1. Clone the repository
  2. Run ./scripts/setup
  3. Now you can run cargo run <arguments> --dev to run the CLI tool

Dev-Container

TODO

CI Pipeline

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.


Templates

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.


.templify

The .templify file contains metadata about the template. It is a key-value file with the following keys:


Usage

tpy [command]

Commands:

help

tpy help

Displays help for templify.

version

tpy version

Displays the current version of templify.

init

tpy init

Initializes templify in the current directory.

new

tpy new <template-name>

Creates a new template with the given name.

load

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.

list

tpy list

Lists all available templates in the current project.

generate

tpy generate <template-name> <given-name>

Generates a file from the given template.


Placeholders

Case conversion

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:


templify-vault

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

Bugs


Release Notes

v1.0.0


by Philipp B.