Skip to content

Commit

Permalink
document usable hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Mar 7, 2020
1 parent 7c3d918 commit 6654db9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
31 changes: 29 additions & 2 deletions plugins/exec/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Exec Plugin

Tap into select hooks and run a command on the terminal
Tap into select hooks and run a command on the terminal.

Tapable hooks, in call order:

- beforeRun
- beforeShipIt
- afterAddToChangelog
- beforeCommitChangelog
- version
- afterVersion
- publish
- afterPublish
- afterRelease
- afterShipIt

Don't see the hook you want? Try making a pull request if you can figure out how to make that type of hook to work!

## Installation

Expand All @@ -14,10 +29,22 @@ yarn add -D @auto-it/exec

## Usage

Here is an example of replacing the `npm` plugins with a light-weight version.

All args to a hook are exposed on the process in enviroment variables.
The format looks like `$ARG_0`, `$ARG_1`, and so on.
Please look at the docs for [writing plugins](../../docs/pages/writing-plugins.md) for more detail on what's available.

```json
{
"plugins": [
["exec"]
[
"exec",
{
"version": "npm version $ARG_0",
"publish": "npm publish && git push --tags"
}
]
// other plugins
]
}
Expand Down
24 changes: 5 additions & 19 deletions plugins/exec/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-lonely-if */
/* eslint-disable @typescript-eslint/no-explicit-any */

import { Auto, IPlugin } from '@auto-it/core';
import {
makeHooks,
Expand Down Expand Up @@ -87,7 +88,7 @@ export default class ExecPlugin implements IPlugin {

/** Tap into auto plugin points. */
apply(auto: Auto) {
Object.entries(this.options).map(([key, command]) => {
Object.entries(this.options).forEach(([key, command]) => {
const name = key as keyof IExecPluginOptions;

/** Tap a hook if possible */
Expand All @@ -96,6 +97,7 @@ export default class ExecPlugin implements IPlugin {

if (
name === 'SyncWaterfallHook' ||
name === 'AsyncSeriesBailHook' ||
name === 'AsyncSeriesWaterfallHook'
) {
auto.logger.log.error(
Expand All @@ -108,7 +110,7 @@ export default class ExecPlugin implements IPlugin {
name === 'AsyncParallelHook'
) {
hook.tap(this.name, (...args: any[]) => {
return execSync(command, {
execSync(command, {
stdio: 'inherit',
env: {
...process.env,
Expand All @@ -121,22 +123,6 @@ export default class ExecPlugin implements IPlugin {
}
});
});
} else if (
name === 'AsyncSeriesBailHook'
) {
hook.tap(this.name, (...args: any[]) => {
return execSync(command, {
env: {
...process.env,
...fromEntries(
args.map((arg, index) => [
`ARG_${index}`,
JSON.stringify(arg)
])
)
}
});
});
}
};

Expand Down

0 comments on commit 6654db9

Please sign in to comment.