|
| 1 | +# Templify |
| 2 | + |
| 3 | +**Standardize and accelerate the creation of templates-based projects using definining placeholders across any kind of project** |
| 4 | + |
| 5 | +Templify is a Maven plugin that helps you generate templates-based from a predefined project using a YAML-based configuration. It supports advanced transformations such as XPath-based replacement in XML files – ideal for managing complex project scaffolding and enforcing consistency. |
| 6 | + |
1 | 7 | [](https://github.com/thoughtworks/templify/actions/workflows/gitAction.yml) |
2 | 8 |
|
3 | 9 | --- |
4 | 10 |
|
5 | | -# Templifly |
| 11 | +## What does it do? |
6 | 12 |
|
7 | | -Templifly is a Maven plugin designed to simplify the process of managing and automating template-based configurations in your projects. By mapping key files—such as XML, JSON, YAML, Java code, or even plain text—Templifly allows you to define placeholders and automate their replacement in a centralized and flexible way. |
| 13 | +Templify automates the generation of templates by: |
8 | 14 |
|
9 | | -Instead of manually editing repetitive elements across files, you can manage everything through a single configuration file. Placeholders are automatically replaced with the appropriate values during the build process, making your setup faster, more reliable, and less error-prone. This plugin supports structured data formats like XML and JSON and can handle custom elements in Java files, offering flexibility for unique project requirements. |
| 15 | +- Reading a YAML config file (`maven-templify.yml`) |
| 16 | +- Loading project files from a directory |
| 17 | +- Applying structured transformations (like XPath replacements in XML) |
| 18 | +- Outputting a complete, placeholders templates-based ready to integrate with your Backstage, Jinja and so on |
10 | 19 |
|
11 | 20 | --- |
12 | 21 |
|
13 | | -## Plugin current status |
14 | | -The plugin is currently in development and is ready for early-stage adoption and validation. |
15 | | -Today, the plugin supports: |
16 | | -* XML |
17 | | -* YAML |
18 | | -* JSON |
19 | | -* Plain text |
20 | | -* Java files and packages |
| 22 | +## Who is it for? |
21 | 23 |
|
| 24 | +Templify is built for: |
22 | 25 |
|
23 | | -## Quickstart |
| 26 | +- **Base Platform teams** creating reusable service templates |
| 27 | +- **Developers** automating repetitive setup tasks |
| 28 | +- **Organizations** seeking consistent project standards and faster delivery |
24 | 29 |
|
25 | | -### Requirements |
26 | | -The basic requirements to use the Templifly-templater plugin are as follows: |
| 30 | +--- |
27 | 31 |
|
28 | | -* JDK11+ |
29 | | -* Apache Maven 3.9.1 |
| 32 | +## How it works |
30 | 33 |
|
31 | | -## Getting Started |
32 | | -To start using the plugin, you are going to need to adjust the configuration file. |
33 | | -The configuration file is `maven-templifly.yml`. After the adjusment of the configurationfile, you will need to run the command below: |
| 34 | +You define: |
34 | 35 |
|
| 36 | +- A **template folder** containing your base project |
| 37 | +- A **YAML config file** that describes: |
| 38 | + - Which files to transform |
| 39 | + - How to match content (XPath for XML) |
| 40 | + - What to replace |
| 41 | + |
| 42 | +Templify will process the files and generate a project in a specified destination. |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## 🧪 Example usage |
| 47 | + |
| 48 | +### 1. Prepare your config file |
| 49 | + |
| 50 | +`maven-templify.yml`: |
| 51 | + |
| 52 | +```yaml |
| 53 | +steps: |
| 54 | + - kind: XmlHandler |
| 55 | + apiVersion: v1 |
| 56 | + spec: |
| 57 | + - files: |
| 58 | + - pom.xml |
| 59 | + placeholders: |
| 60 | + - match: /project/groupId |
| 61 | + replace: templify.param.groupId |
| 62 | + - match: /project/artifactId |
| 63 | + replace: templify.test.replace.map.artifactId |
| 64 | + - match: /project/dependencies/dependency/scope[text()='test'] |
| 65 | + replace: templify.replace.map.scopes |
| 66 | + - files: |
| 67 | + - xmls/generic_1.xml |
| 68 | + placeholders: |
| 69 | + - match: /note/heading |
| 70 | + replace: New Reminder |
| 71 | + - files: |
| 72 | + - xmls/complex/generic_2.xml |
| 73 | + placeholders: |
| 74 | + - match: /bookstore/book/author[text()='Kurt Cagle'] |
| 75 | + replace: templify.kurtCagle |
| 76 | + - match: /bookstore/book/year[text()='2005'] |
| 77 | + replace: templify.NewYear |
35 | 78 | ``` |
| 79 | +
|
| 80 | +--- |
| 81 | +
|
| 82 | +### 2. Run the plugin |
| 83 | +
|
| 84 | +```bash |
36 | 85 | mvn com.thoughtworks.templify:templify:create |
37 | 86 | ``` |
38 | 87 |
|
39 | | -### Usage of the configuration file. |
40 | | -As mentioned, the plugin supports some file types and we are going to explain the configuration for each supported types. |
41 | | -But first let understand the configuration file structure. |
| 88 | +- |
| 89 | + |
| 90 | +## Template folder structure |
42 | 91 |
|
43 | | -#### Configuration file structure |
44 | | -The configuration file is in a `Yaml` type and has the following structure: |
45 | 92 | ``` |
46 | | -settings |
47 | | -└── placeholder |
48 | | -| └── prefix |
49 | | -| └── suffix |
50 | | -steps |
51 | | -└── - kind |
52 | | -| └── apiVersion |
53 | | -| └── spec |
54 | | -| └── - files |
55 | | -| └── placeholders |
56 | | -| └── - match |
57 | | -| └── replace |
| 93 | +
|
| 94 | +📁 target/template/ |
| 95 | +├── pom.xml |
| 96 | +├── xmls/ |
| 97 | +│ ├── generic_1.xml |
| 98 | +│ └── complex/generic_2.xml |
| 99 | +└── other project files... |
58 | 100 | ``` |
59 | | -#### 1. **settings** |
60 | | - - **placeholder**: Configures how placeholders are identified within files. |
61 | | - - **prefix**: Specifies the prefix marking the start of a placeholder. |
62 | | - - **suffix**: Specifies the suffix marking the end of a placeholder. |
63 | | - - This setup lets the plugin locate variables needing replacement in the template files and if it is not defined the default prefix and sufix at the placeholder will be `{{` and `}}`. |
64 | | -#### 2. **steps** |
65 | | - - A list of actions, with each item defining a specific configuration step. |
66 | | - - **kind**: Identifies the type of action to perform at this step. Ex: XmlHandler, YmlHandler, JavaHandler... |
67 | | - - **apiVersion**: Defines the API version used for executing this action. today we have only the `v1` |
68 | | - - **spec**: Contains instructions for the step, including files and placeholders to be processed. |
69 | | - - **files**: Lists the files and paths that will be processed for replacements. The path should be informed from the root of the project |
70 | | - - **placeholders**: Specifies the replacement operations in each file. |
71 | | - - **match**: The text or pattern the plugin will locate within the file. |
72 | | - - **replace**: The text that will replace the `match`. |
73 | | - |
74 | | -### Summary of How It Works |
75 | | -This configuration allows the plugin to: |
76 | | -- Identify variables with placeholders using the specified `prefix` and `suffix`. |
77 | | -- Execute specific steps (`steps`) to replace values in designated files according to the `placeholders` rules in each step. |
78 | | - |
79 | | - |
80 | | -### More Information |
81 | | -For detailed documentation and advanced configuration options, please refer to our [Templifly Wiki](https://github.com/thoughtworks/Templify/wiki) |
| 101 | + |
| 102 | +Templify will copy this structure to the `target/template` folder and apply the transformations defined in `maven-templify.yml`. |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## What makes it powerful? |
| 107 | + |
| 108 | +- 🎯 **XPath JSONPath, YAMLPath, JAva Procjects and Plain Text support** for precise targeting your project nodes |
| 109 | +- 🔄 **Batch transformations** across multiple files |
| 110 | +- 💼 **Custom parameter references** (e.g., `templify.param.groupId`) |
| 111 | +- 🧩 **Composable templates** for different types of services or modules |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Learn More |
| 116 | + |
| 117 | +- [Templify Wiki](https://github.com/thoughtworks/templify/wiki) |
| 118 | + |
| 119 | +-- |
| 120 | + |
| 121 | +## Contributing |
| 122 | + |
| 123 | +Spotted a bug or have a new use case in mind? We welcome contributions, ideas, and questions. Open an [issue](https://github.com/thoughtworks/templify/issues) or submit a PR! |
0 commit comments