Tired of repetitive, boilerplate code? forge-template
is here to rescue you! No more wasting time on generic, repetitive tasks! With forge-template
you can quickly generate templates tailored to your project requirements, letting you focus on what really matters, your code.
-
forge-template
- Table of Contents
- Installation
- Basic Syntax
- Defining a file template
- Defining a directory template
- Defining a directory template Example
-
Using Terminal commands
- Help Tool
- Terminal command for creating a file template
- Terminal command for creating a directory template
- Terminal command for creating a directory from a template
- Terminal command for creating a file from a template
- Terminal command for deleting a directory template
- Terminal command for deleting a file template
If you have Go installed on your system, you can use the go install
command to install forge-template
. Run the following command in your terminal:
go install github.com/hanskrohn/forge-template@latest
- Navigate to the Releases page.
- Download the appropriate file for your Unix/Linux system.
- After downloading the file open a terminal and run the following command to rename the download
mv ~/PATH_TO_DOWNLOAD/downloaded_file ~/PATH_TO_DOWNLOAD/forge-template.
- Move the renamed file to a directory in your PATH. It can be done with the command below
mv ~/PATH_TO_DOWNLOAD/forge-template ~/DESIRED_LOCATION_PATH
If you are unsure how to add a directory to your path you can follow the commands below
mkdir ~/bin
echo 'export PATH="$PATH:$HOME/bin"' >> ~/.bashrc # For bash
echo 'export PATH="$PATH:$HOME/bin"' >> ~/.zshrc # For zsh
mv ~/PATH_TO_DOWNLOAD/forge-template ~/bin
- Navigate to the Releases page.
- Download the appropriate file for your Windows system.
- After downloading the file open a Command Prompt in administrator mode and run the following command to rename the download
rename C:\PATH_TO_DOWNLOAD\downloaded_file forge-template
- Move the renamed file to a directory in your PATH. It can be done with the command below
move C:\PATH_TO_DOWNLOAD\forge-template C:\DESIRED_LOCATION_PATH
If you are unsure how to add a directory to your path you can follow the commands below
mkdir C:\bin
setx PATH "%PATH%;C:\bin"
move C:\PATH_TO_DOWNLOAD\forge-template C:\bin
To define variable values in your template simply wrap the variable with <>
, like this <<VARIABLE_NAME>>
. When creating the template we will reference the the VARIABLE_NAME
and prompt you to provide values.
In the case your code requires the symbols <>
wrapped around a variable, please use the \
to escape the variable.
Example:
import React from 'react';
interface <<ComponentName>>Props {}
// Only need 1 escape over here *
export const <<ComponentName>>: React.FC\<<<ComponentName>>Props> = ({ }) {
return <>Hello From <<ComponentName>></>;
}
To define a file template run forge-template
and select the Create File Template
option. This will open up tool tips that prompt you for the file name and template code. Once this data is saved, you can run forge-template
again and select Create File From Template
option. This will open a tool tip to select the file template you want to create, and prompt you to provide variables if necessary.
- Run
forge-template
and selectCreate File Template
- Provide the name
controller.tsx
in the input box and pressCtrl+s
to save - Provide the following template code in the text area and press
Ctrl+s
to save
import React from 'react';
interface <<ComponentName>>Props {}
export const <<ComponentName>>: React.FC\<<<ComponentName>>Props> = ({ }) {
return <>Hello From <<ComponentName>></>;
}
- Run
forge-template
again and selectCreate File From Template
- Use the arrow keys to select
controller.tsx
- Provide the value
User
when prompted to provide a value forComponentName
. PressCtrl+s
to save - View the newly generated file with your favorite text editor
To define a directory template run forge-template
and select the Create Directory Template
option. This will open up tool tips that prompt you for the directory name and template code. Once this data is saved, you can run forge-template
again and select Create Directory From Template
option. This will open a tool tip to select the file template you want to create, and prompt you to provide variables if necessary.
- Use
<<>>
to define variable values - The root element should have no leading symbols or spaces
- Use
.
as the root element to define the directory structure to build out from current directory - Child directories and files should have 3 leading spaces. If you have more than 3 you will get an error and less than three will not result in a child element being created
- Directories are prefaced with
|--
- Files are prefaced with
|-
- Run
forge-template
and selectCreate Directory Template
- Provide the name
basic-structure
in the input box and pressCtrl+s
to save - Provide the following template code in the text area and press
Ctrl+s
to save
basic-project
|-- src
|- index.js
|-- test
|-- index.test.js
- Run
forge-template
again and selectCreate Directory From Template
- Use the arrow keys to select
basic-structure
- View the newly generated file with your favorite text editor
If you forget any command and need help on the fly use the --help
or -h
flag. This flag is used at the end of the command you want to run to explain the final command.
For example, forge-template --help
will open a tool tip explaining the forge-template command, possible flags, and available commands that can be used.
To create a file template, use the following command in terminal
forge-template create-template --file --templateName <DESIRED_TEMPLATE_NAME>
Alternatively, this command can be written short form as
forge-template ct -f -t <DESIRED_TEMPLATE_NAME>
For more info run
forge-template ct -h
To create a directory template, use the following command in terminal
forge-template create-template --directory --templateName <DESIRED_TEMPLATE_NAME>
Alternatively, this command can be written short form as
forge-template ct -d -t <DESIRED_TEMPLATE_NAME>
For more info run
forge-template ct -h
To create a directory from a template, use the following command in terminal
forge-template create-directory --templateName <YOUR_TEMPLATE_NAME>
Alternatively, this command can be written short form as
forge-template cd -t <YOUR_TEMPLATE_NAME>
For more info run
forge-template cd -h
To create a file from a template, use the following command in terminal
forge-template create-file --filename <DESIRED_FILE_NAME> --templateName <YOUR_TEMPLATE_NAME>
Alternatively, this command can be written short form as
forge-template cf -f <DESIRED_FILE_NAME> -t <YOUR_TEMPLATE_NAME>
For more info run
forge-template cf -h
To delete a directory template, use the following command in terminal
forge-template delete-template --directory --templateName <DESIRED_TEMPLATE_NAME>
Alternatively, this command can be written short form as
forge-template dt -d -t <DESIRED_TEMPLATE_NAME>
For more info run
forge-template dt -h
To delete a file template, use the following command in terminal
forge-template delete-template --file --templateName <DESIRED_TEMPLATE_NAME>
Alternatively, this command can be written short form as
forge-template dt -f -t <DESIRED_TEMPLATE_NAME>
For more info run
forge-template dt -h