Run a command and then all registered hook(s).
$ npm install --save post-command-hook
or
$ yarn add post-command-hook
Let's suppose we want to add esdoc to our project, create config file and generate a documentation. To achieve that we could create a file esdoc-setup.js
and use the following snippet:
const PostCommandHook = require('post-command-hook');
const postCommandHook = new PostCommandHook({ command: 'npm', args: ['i', '--save-dev', 'esdoc', 'esdoc-standard-plugin'] });
postCommandHook.use(() => {
require('fs').writeFile("./.esdoc.json", `{
"source": "./lib",
"destination": "./docs",
"plugins": [{"name": "esdoc-standard-plugin"}]
}`, (err) => {
if (err) {
console.log(err);
}
});
}).use({ command: './node_modules/.bin/esdoc' });
(async () => {
await postCommandHook.run();
})();
and run it:
$ node esdoc-setup.js
Constructs an instance of PostCommandHook class providing baseCommand
and execaOptions
. The baseCommand
is an object with the following keys:
Type: object
Base command to be issued. It must have required command
key, args
is optional one.
Type: string
Required: true
A command that should be issued.
Type: array
A command arguments to construct the whole command.
Type: string
A message to be displayed before execution of the specified command.
Type: string
A message to be displayed after execution of the specified command.
Options to be used while executing a command. Default value is { stdio: "inherit" }
. See execa documentation for details.
Registers specified plugin that will be issued after execution of the base command. Could be chained.
Type: object
, function
or an instance of class responding to .run
.
Instructs to keep already performed commands in the registry and not to run them again. It allows you to add a plugins which are going to be ran without executing previously issued commands.
Type: boolean
Whether to issue a commands which are previously have been executed.
Executes the base command and then executes all registered plugins.
Type: object
Type: boolean
Instructs to not throw an error if any happens and silently skip it. Note that this option will not apply for base command execution hence if base command fails an error will be thrown.
MIT © Rushan Alyautdinov