Skip to content
/ mig Public

CLI tools for create template based project from github repository

License

Notifications You must be signed in to change notification settings

gomig/mig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

First, make sure you have Go installed.

go install github.com/gomig/mig

Update

Update cli tools to latest version.

mig update

Create New Project

mig new myApp

Enter your repository and configure what you want. By default mig use gomig/boilerplate template.

Create Project From Custom Branch Or Tag

mig new myApp -b v1.2.3

Create From Private Repository

For creating project from private github repository you need to store your github auth information. You must get personal access token from your github account.

mig new myApp -a main

Add New Credential Or Override

# Command
mig auth [key] [user] [access token]

# Usage
mig auth main johndoe asdfvzxcvq123asdfz

Delete Credential

# Command
mig unauth [key]

# Usage
mig unauth main

List Registered Credentials

mig users

# Output
┌───┬──────────────────┬──────────┐
│ # │ AUTHENTICATE KEY │ USERNAME │
├───┼──────────────────┼──────────┤
│ 1 │ main             │ johndoe  │
└───┴──────────────────┴──────────┘

Template Repository Guide

Mig compile repository template base on Go Text Template Library with <% %> delimeter. Each repository must contain mig.json configuration file in th root of repository.

NOTE: You can use user entered app name with .name variable or __name__ placeholder in your template syntax.

NOTE: You can use a unique project key with .key variable or __key__ placeholder. Each time you create new project mig generate new key for your project.

Extra Template Functions

You can use follwing helper functions in your template syntax:

iif

Return quick answer base on condition.

Your gender is: <% iif .isMale "Male" "Female" %>

oneOf

Check if value contains

OK: <% oneOf .name "John|Jack" %>

uuid

Generate unique uuid string.

const identifier = "<% uuid %>";

key32

Generate 32-character unique string key.

const accessKey = "<% key32 %>";

key64

Generate 64-character unique string key.

const accessKey = "<% key64 %>";

key96

Generate 96-character unique string key.

const accessKey = "<% key96 %>";

key128

Generate 128-character unique string key.

const accessKey = "<% key128 %>";

Extra Template Signs

Sometimes you want to comment code in template by default and compiled to code under some conditions.

  • // <% This line translated to <% on compile time. You could use template sign with comment.
  • //- This comment sign remove from start of line on compile time.
  • "-<% Unquote value of expression on compile time.
  • %>-" Unquote value of expression on compile time.
// Create new instance of <% .appName %>
var app = new App("__APP__");

// This code only uncommented if web parameters equal y
// <% if eq .web "y" %>
//- var client = new HttpClient();
//- client.initialize();
//- app.Client = client;
// <% end %>

Configuration

To configure your project template you need to put mig.json file in the root of your project. All configuration file rules value accessable in template syntax with rule name.

  • name: Template name.

  • intro: Introduction text to show before start configuration.

  • message: Final message to show after project creation.

  • rules: List of question to ask from user to configure template.

    • name: Name of rule. You can use rule answer in your template with rule name (.web, .app_name, ...).
    • default: Default rule value if user leave answer empty.
    • placeholder: A placeholder text to replace with rule answer. You can use placeholder in file name or string quotes.
    • desc: Rule description.
    • options: List of valid options for rule. If options not defined any text allowed.
    • files: File proccess conditions. You can define which file must included on final result based on rule value.
  • statics: List of static assets to not compile with template engine.

  • ignores: List of repository files to ignore.

  • scripts: List of scripts to run after project create. Script must splited to array of args.

{
  "name": "My Template",
  "intro": "You need git and node installed on your system.",
  "message": "Visit config/config.json to configure app port and information",
  "rules": [
    {
      "name": "app_name",
      "placeholder": "__APP__",
      "desc": "application name"
    },
    {
      "name": "web",
      "default": "n",
      "desc": "include web assets",
      "options": ["y", "n"],
      "files": {
        "n": ["console.md"], // console.md only included if web answer was n
        "y": ["web.md", "web.js", "views", "public", "src/app.js"] // this files and directory not listed if answer was n
      }
    },
    {
      "name": "locale",
      "default": "en",
      "placeholder": "__LOCALE__"
    }
  ],
  "statics": ["public/favicon.ico", "assets/icons"],
  "ignores": ["readme.md"],
  "scripts": [
    ["npm", "install"],
    ["git", "init"],
    ["git", "add", "."],
    ["git", "commit", "-m", "'initialize app'"]
  ]
}

About

CLI tools for create template based project from github repository

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages