run
Declarative Hooks run
are for executing commands. Some interesting usage examples are:
- Install dependencies in the project;
- Execute commands from any tool that is part of the Stack;
- Execute configurations through shell or batch scripts.
Below is a simple example of a Declarative Hook of type run
:
hooks:
- type: run
trigger: before-input
commands:
- echo hello from before-input!
- echo you can define multiple commands in a run hook!
When you apply the Template/Plugin that defines this Declarative Hook, before asking for input parameters, the console shows the following sentences:
hello from before-input!
you can define multiple commands in a run hook!
.
It is possible to use conditional operators with the conditions
parameter in a Hook, check the example below:
name: my-plugin
description: Describe your plugin explaining its purpose
types:
- app
inputs:
- label: Do you want to install the dependencies?
type: bool
name: install_dependencies
hooks:
- type: run
trigger: after-render
commands:
- echo Installing dependencies
- npm install
condition:
variable: install_dependencies
operator: "=="
value: true
In this example, the boolean type input
asks the user a question to install dependencies. The condition
causes the Hook to execute in this case if the answer is true ( operator ==
and value true
). The npm install
commands will be executed to install the dependencies.
You can define different commands in each operating system. See the example below:
hooks:
- type: run
trigger: before-input
working-dir: "{{project_name}}/some/dir"
linux:
- echo hello from before-input on linux!
windows:
- cmd /C echo hello from before-input on windows!
mac:
- echo hello from before-input on mac!
In this case, when applying the Template/Plugin, the message that appears on the console will be different for each operating system. The supported operating systems are:
linux
mac
windows
Command chaining and output redirection operators (|, ||, &&, &, >, >>, ;) are not supported and are interpreted as strings when executed.
Command run
on Windows
To run other applications through run
on Windows, use one of the examples below:
- Using
cmd
. In this case, it opens an extra CMD window when the plugin is being applied, but then it closes automatically.
hooks:
- type: run
trigger: after-render
working-dir: "{{project_name}}/some/dir"
linux:
- npm install
Windows:
- cmd /c npm install
mac:
- npm install
- Call the npm binary directly, here npm runs in the same window:
hooks:
- type: run
trigger: after-render
working-dir: "{{project_name}}/some/dir"
linux:
- npm install
Windows:
- npm.cmd install
mac:
- npm install
Available Actions from Declarative Hook run
trigger:
Field to set triggers to tell you when a command execution should occur.
before-input
:
Executes the hook commands before receiving the input parameters from the user.
trigger: before-input
before-render
:
Execute hook commands before the Template generates files in the project.
trigger: before-render
after-render
:
Execute hook commands after the Template generates files in the project.
trigger: after-render
working-dir:
(Opcional)
Allows you to define a directory related to a project root where commands will be executed. When not entered, commands will execute in the project root. You can use Jinja expressions in the working-dir
field, for example:
working-dir: "{{project_name}}/some/dir"
commands:
Allows you to define one or more commands to execute.
commands:
- echo hello from before-input!
- echo you can define multiple commands in a run hook!
- To use the commands in Windows, the CMD tool needs to run with the
cmd /c
argument. See an example below:
commands:
- cmd /c echo hello from before-input!
- cmd /c echo you can define multiple commands in a run hook!
linux:
(Opcional)
It allows you to define one or more commands, specifying the execution on Linux systems.
linux:
- npm install
windows:
(Opcional)
Allows you to define one or more commands, specifying execution on Windows systems.
windows:
- cmd /c npm install
mac:
(Opcional)
It allows you to define one or more commands, specifying execution on macOS systems.
mac:
- npm install
On the Declarative Hook's run
actions, command chaining, and output redirection operators (|, ||, &&, &, >, >>, ;) are not supported and are interpreted as strings when executed.
Read more
Was this page helpful?