cortojs v1.21.1
corto
Boilerplate app snippets
Quick start
# Inits a new corto
corto init --directory ./my-template
# Add a corto file
cat <<README > ./my-template/README.md
{{ def.name }}
===
{{ def.about }}
README
# Installs new corto
corto install \
--from ./my-template \
--target ./foo \
--def.name project \
--def.about 'a cool project'
# Verifies interpolation worked
cat ./foo/README.md
project
===
a cool project
You can configure stuff like default values and hooks:
- via cli arguments
- via a config file (default is a
corto.json
file inside the template's folder)
If both are used, cli arguments gets precedence but not exclusivity, meaning configurations will be merged.
Install
# Install from local directory
corto install /path/to/templates
# Install git from http
corto install http://github.com/corto/parceljs
# Install git from ssh
corto install git@github.com:corto/parceljs
Options
We use clipop for declaring options
corto install <corto>
# Permits copying inside already existing directories
--allow-exists boolean
# Permits copying over non-empty directories
--allow-non-empty boolean
# Path to a json file with corto config
--config string
# Dictionnary of substitutions
--def object<string>
# Dictionnary of extra
--extra object<string>
# Do not apply configuration from corto.json
--ignore-config boolean
# Hooks (view below)
--hooks object
# Dictionnary of options
--opt object<string>
# Regular expression to use for interpolation
--pattern string
# Strategy used for stumbling upon existing locations
--strategy string
# Fine grain strategies
--strategies object<string>[]
# Output verbosity
--verbose boolean
corto.json
All these properties (except config
) can saved inside a corto.json. Just camel case option names:
{
"corto": {
"name": "mycorto",
"version": "1.0.0"
},
"allowExists": false,
"pattern": "<(.+)>",
"required": {
"field": true
},
"def": {
"name": "some default name"
},
"hooks": {
"pre": [
"git init"
],
"post": [
"git add .",
"git commit -am First",
"npm install"
]
}
}
Hooks
Hooks can be applied before everything (pre
) or after everything (post
)
Hook literal commands
Hooks are commands that are run inside the target directory, for example:
npm install
Hook template commands
You can also use templating:
{
"opt": {
"packageManager": "npm" // default package manager
},
"schema": {
"packageManager": {
"oneOf": ["npm", "yarn"] // setting accepted package managers
}
},
"hooks": {
"post": [
// install node dependencies
"{{ opt.packageManager }} install"
]
}
}
corto install ./my-corto --opt.packageManager yarn # will use yarn instead of npm
Command interface
There is a limitation to string literals: they don't encapsulate between-quotes content, so the following command:
do-something --command 'do something cool'
will be run such as:
"do-something" "--command" "do" "something" "cool"
To work around that problem, you can use the command interface (templating allowed):
{
"opt": {
"score": 0
},
"hooks": {
"post": [
{
"command": "do-something",
"args": [
"--command",
"do something cool"
],
"condition": "opt.score > 100" // optional
}
]
}
}
Loop support
{
"opt": {
"path": "a/bc/d/d/e/f"
},
"hooks": {
"pre": [
{
"for": "opt.path.split('/')",
"each": "mkdir {{ item }}"
}
]
}
}
Basic fs support
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago