First, make sure you have Go installed.
go install github.com/gomig/mig
Update cli tools to latest version.
mig update
mig new myApp
Enter your repository and configure what you want. By default mig use gomig/boilerplate template.
mig new myApp -b v1.2.3
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
# Command
mig auth [key] [user] [access token]
# Usage
mig auth main johndoe asdfvzxcvq123asdfz
# Command
mig unauth [key]
# Usage
mig unauth main
mig users
# Output
┌───┬──────────────────┬──────────┐
│ # │ AUTHENTICATE KEY │ USERNAME │
├───┼──────────────────┼──────────┤
│ 1 │ main │ johndoe │
└───┴──────────────────┴──────────┘
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.
You can use follwing helper functions in your template syntax:
Return quick answer base on condition.
Your gender is: <% iif .isMale "Male" "Female" %>
Check if value contains
OK: <% oneOf .name "John|Jack" %>
Generate unique uuid string.
const identifier = "<% uuid %>";
Generate 32-character unique string key.
const accessKey = "<% key32 %>";
Generate 64-character unique string key.
const accessKey = "<% key64 %>";
Generate 96-character unique string key.
const accessKey = "<% key96 %>";
Generate 128-character unique string key.
const accessKey = "<% key128 %>";
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 %>
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.
- name: Name of rule. You can use rule answer in your template with rule name (
-
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'"]
]
}