CLI
Documentation for the Command Line Interface
Documentation for the Command Line Interface
Lore's CLI is designed to be overridden and extended. Every command is implemented as a separate package, and the CLI dynamically builds the interface based on the packages provided to it in a configuration object.
A portion of the configuration object provided to it by default looks like this:
{
// ...,
commands: {
new: local("lore-generate-new"),
tutorial: local("lore-tutorial"),
extract: {
description: "Create files that mirror the blueprint behavior",
commands: {
action: local("lore-extract-action"),
reducer: local("lore-extract-reducer")
}
},
generate: {
description: "Generate common project files",
commands: {
collection: local("lore-generate-collection"),
component: local("lore-generate-component"),
generator: local("lore-generate-generator"),
hook: local("lore-generate-hook"),
model: local("lore-generate-model"),
reducer: local("lore-generate-reducer"),
surge: local("lore-generate-surge"),
github: local("lore-generate-github")
}
}
}
}
If you examine the commands in the CLI, you'll notice they mirror the hierarchy of this object. For example, the command lore generate model
maps to commands.generate.model
.
If you open up the .lorerc
file at the root of your project, it should look something like this:
{
"generators": {
"language": "es6"
},
"commands": {}
}
The CLI will read this file when you run commands from within a project, and will use it to override the default configuration. This means that if you want to override the way models
are generated for example, you simply need to provide an alternate implementation for that command, like this:
{
"generators": {
"language": "es6"
},
"commands": {
"generate": {
"commands": {
"model": "lore-generate-alternate-model"
}
}
}
}
The config above would cause the CLI to use the lore-generate-alternate-model
package instead of the default lore-generate-model
package when it executed the command lore generate model
.
You can also use this behavior to extend the CLI, by providing completely new commands, and you also provide a local path to your package as well. For example, let's say you wanted to add a command that would analyze your routes.js
file and print out a flat list of all valid routes in your application. You could add that command to the CLI like this:
{
"generators": {
"language": "es6"
},
"commands": {
"routes": {
"description": "Helper commands for analyzing application routes",
"commands": {
"list": "/Users/username/commands/lore-routes-list"
}
}
}
}