Making your own tasks
Create either ~/.mrm/<TASK>/index.js
or ~/dotfiles/mrm/<TASK>/index.js
. If <TASK>
is the same as one of the default tasks your task will override the default one.
Tip: Tasks can be packaged into presets; if you want to share them, see Making presets.
Basic tasks
The simplest task could look like this:
Tasks can also be async by adding the async
keyword or returning a Promise
.
Tasks with dependencies
If your tasks have dependencies (such as mrm-core
) you should initialize the mrm
folder as an npm module, and install your dependencies there:
Tip: mrm-core is a library of utility helpers for writing Mrm tasks, that has functions to work with common config files (JSON, YAML, INI, Markdown), npm dependencies, etc.
mrm-core
) and parameters
Tasks with utility helpers (Let’s take a look at a more complex task.
Have a look at mrm-core docs for more utility helpers, and the default tasks for examples.
Configuration prompts
Configuration prompts allows you to configure tasks, by specifying options in the config file, via command line parameters, or via an interactive prompt questions.
Here’s a basic configuration prompt:
Tip: Mrm supports more complex prompts too — have a look at Inquirer.js docs.
We pass all parameters to Inquirer.js, unless they have the config
type, which means this parameter could only be defined via the config file. Use it for complex data, like objects.
The default
can be a literal value, like in the example above, or a function that receives an object with config values and command line overrides:
This is different from the default Inquirer.js behavior and works consistently in Mrm’s interactive and non-interactive modes.
Use the validate()
method to make a parameter required:
In this case the only ways to override the default walue are a config file, or a command line parameter.