Giter Club home page Giter Club logo

go-giter8's Introduction

go-giter8

btnguyen2k/go-giter8 is a fork of savaki/go-giter8, which is a command line tool to generate files and directories from templates published on git repository. It's implemented in Go and can produce output for any purpose.

Features:

  • Generate template output from any git repository.
  • Generate template output from local directory (protocol file://).
  • Support scaffolding.

Latest version: v0.4.3.

Installation

You can install go-giter8 using the standard go deployment tool. This will install g8 as $GOPATH/bin/g8:

go get github.com/btnguyen2k/go-giter8/g8

or you can specified a specific version:

go get github.com/btnguyen2k/go-giter8/[email protected]

Upgrading

At any point you can upgrade g8 using the following:

go get -u github.com/btnguyen2k/go-giter8/g8

or you can specified a specific version:

go get -u github.com/btnguyen2k/go-giter8/[email protected]

GO111MODULE mode must be turned on in order to install/update go-giter8.

Giter8 template

For information on Giter8 templates, please see http://www.foundweekends.org/giter8/.

Summary of a Giter8 template project structure:

<root>/
└── src/main/
    ├── g8/
    │   └── <template source files & directories>
    └── scaffolds/
        ├── <name1>/
        │   ├── default.properties
        │   └── <source files & directories of scaffold 1>
        ├── <name2>/
        │   ├── default.properties
        │   └── <source files & directories of scaffold 2>
        │   ...
        └── <nameN>/
            ├── default.properties
            └── <source files & directories of scaffold N>

Usage

Template repositories must reside in a git repository and be named with the suffix .g8. The syntax of go-giter8 is slightly different from the original giter8.

New Project

To create a new project from template, for example, btnguyen2k/goapi.g8:

$ g8 new btnguyen2k/api.g8

By default, template is cloned from Github. Use full repo url to create project from template resided in other git server:

$ g8 new https://gitlab.com/btnguyen2k/goapi.g8

go-giter8 uses your git binary underneath the hood so any settings you've applied to git will also be picked up by g8.

go-giter8 can also generate template output from local directory (useful when testing template before publishing):

$ g8 new file:///home/btnguyen2k/workspace/goapi.g8

Files & directories under /src/main/g8/ are used to generate project.

Scaffolds under /src/main/scaffolds/ are copied to .g8/ under project's target directory.

Template placeholders and substitutions are defined in default.properties file. See section Formatting Template Fields below.

Scaffolding

Scaffolds can be generated by standing at generated project's root directory and run the following command:

$ g8 scaffold <scafold-name>

For example:

$ g8 scaffold bodao_mysql

Scaffold placeholders and substitutions are defined in default.properties files. See section Formatting Template Fields below.

Scaffolding is available since v0.4.0.

Formatting Template Fields

go-giter8 has built-in support for formatting template fields. Formatting options can be added when referencing fields. For example, the name field can be formatted in upper camel case with:

$name;format="Camel"$

If name field has value myName, the above formatting will transform to MyName.

The formatting options are:

FuncName | Alternative Name
---------|--------------------------------------------------------------------------------
upper    | uppercase       : all uppercase letters
lower    | lowercase       : all lowercase letters
cap      | capitalize      : uppercase first letter
decap    | decapitalize    : lowercase first letter
start    |                 : uppercase the first letter of each word
word     |                 : remove all non-word letters (only a-zA-Z0-9_)
Camel    |                 : upper camel case (start-case, word-only)
camel    |                 : lower camel case (start-case, word-only, decapitalize)
hyphen   | hyphenate       : replace spaces with hyphens
norm     | normalize       : all lowercase with hyphens (lowercase, hyphenate)
snake    |                 : replace spaces and dots with underscores
packaged |                 : replace dots with slashes (net.databinder -> net/databinder)
random   |                 : appends random characters to the given string

Project level fields are defined in /src/main/g8/default.properties file.

Scaffold level fields are defined in /src/main/scaffolds/<scaffold-name>/default.properties file.

Sample of default.properties:

description  = This template generates a microservices project in Go using Echo framework.
verbatim     = .DS_Store .gitignore .gitlab-ci.yml go.mod go.sum release.sh public/* vendor/* views/*

name         = go_echo-microservices-seed
shortname    = gems
desc         = Microservices project template for Go using Echo
organization = com.github.btnguyen2k
app_author   = Thanh Nguyen <[email protected]>
app_version  = 0.1.0
timezone     = Asia/Ho_Chi_Minh

Special fields:

  • description: description of the template. It will be excluded from substitution list.
  • verbatim: list of file patterns (separated by space, comma, semi-colon or colon) such as *.gif,*.png *.ico. Files matching verbatim pattern are excluded from string template processing. verbatim field will be excluded from substitution list.
  • name: it is used as the name of a project being created. go-giter8 creates a project directory based off that name (normalized) that will contain the template output.

It is recommended that name follows the format [a-zA-Z0-9]+ (only numbers and character). Use camelCase to separate words (not underscores!).

go-giter8's People

Contributors

btnguyen2k avatar savaki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.