#template #generator

app tgm

CLI to manage template repositories

15 releases (9 breaking)

Uses new Rust 2021

0.10.0 Jan 1, 2022
0.9.1 Sep 22, 2021
0.8.1 Sep 26, 2020

#71 in Command line utilities

Download history 3/week @ 2021-09-30 1/week @ 2021-10-07 2/week @ 2021-10-14 16/week @ 2021-10-21 16/week @ 2021-11-04 6/week @ 2021-11-11 23/week @ 2021-11-18 13/week @ 2021-11-25 47/week @ 2021-12-02 14/week @ 2021-12-09 7/week @ 2021-12-16 18/week @ 2021-12-23 42/week @ 2021-12-30 16/week @ 2022-01-06 16/week @ 2022-01-13

92 downloads per month

Apache-2.0

44KB
866 lines

tgm - Template Generator Manager

Build Status tgm Crate dependency status

Generate project structure from git template repository.

Why tgm?

  • Manage all template repositories
  • Create app from template quickly
  • Prompt for template variables

Template repository

Please add template.json file in your template repository, code as following:

{
  "name": "spring-boot-java",
  "repository": "https://github.com/linux-china/spring-boot-java-template",
  "description": "Spring Boot App Java",
  "post_create": "mvn -DskipTests compile",
  "variables": [
    {
      "name": "groupId",
      "description": "Maven groupId"
    },
    {
      "name": "artifactId",
      "description": "Maven artifactId"
    }
  ],
  "files": [
    "pom.xml","src/main/resources/application.properties"
  ]
}

Attention: You can add regex pattern validation for variable's value like following:

    {
      "name": "email",
      "description": "author email",
      "pattern": "[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}"
    }

In the resource files, such as pom.xml, use template variable as following:

<project>
  <groupId>@groupId@</groupId>
  <artifactId>@artifactId@</artifactId>
</project>

default global variables:

  • current_year: current year, such as 2020
  • current_date: current date, format like 08/30/2020
  • os_name: linux, macos, ios, freebsd, dragonfly, netbsd, openbsd, solaris, android, windows
  • os_family: unix, windows
  • os_arch: x86_64, arm

Install & Usage

$ cargo install tgm
$ tgm add linux-china/spring-boot-java-template
$ tgm list
$ tgm create spring-boot-java spring-app-demo

tgm commands:

$ tgm add --name spring-boot-java --repo https://github.com/linux-china/spring-boot-java-template.git --desc "Spring Boot Java template"
  • import template from github's repository
$ tgm import linux-china/spring-boot-kotlin-template
$ tgm import https://github.com/linux-china/spring-boot-java-template
  • remove: remove template
$ tgm remove spring-boot-java
  • create: create app from template
$ tgm create spring-boot-java spring-demo1 

Shell completion

oh-my-zsh

$ tgm complete --oh_my_zsh

tgm will add tgm to plugins in ~/.zshrc.

bash

$ tgm complete --bash > tgm-completion.bash
$ source ./tgm-completion.bash 

References

Dependencies

~9–13MB
~281K SLoC

ga