/templify

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

Primary LanguageRustMIT LicenseMIT


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

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.


Development Installation

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

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:

  • description: A short description of the template
  • path: 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.

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

  • $$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

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)

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

  • no known bugs

  • Refactoring
  • Added variable placeholders
  • Added -reset flag for the reload command
  • Added -force flag for the generate command
  • Added -reload flag for the generate command
  • Added -var flag for the generate command
  • Added -default-var flag for the generate command
  • Short forms for case conversion
  • Added divider selection support in the .templify file
  • Added global flag support
  • Added --quiet global flag
  • Added --dev global flag
  • Added --log-file global flag
  • Initialize test suite
  • CI pipeline for code quality checks

by Philipp B.