Skip to main content

Toolkit

CLI

This CLI is the official scaffolding generator for hermes-io, its generates a simple folder structure that guaranty separation of concerns encompassing pivotal elements such as: Context, useObserver and Observer.

Summary

Installation

npm install hermes-io-cli -g

Usage

This CLI has a set of commands for generate folders and files for hermes-io entities.

Context

By passing the context argument a newly created folder named as 'contexts' is automatically generated. Within this folder, a brand-new Context file is generated, adopting the provided value as its designated name.

hermes-io-cli --context="MyContext"

result:

/contexts/MyContext.js
import { Context } from 'hermes-io';
export const MyContext = new Context('MyContext');

Observer

By passing the observer argument a newly created folder named as 'observers' is automatically generated. Within this folder, a brand-new Observer file is generated, adopting the provided value as its designated name.

hermes-io-cli --observer="MyObserver"

result:

/observers/MyObserver.js
import { Observer } from 'hermes-io';
export const MyObserver = new Observer('MyObserver');

Note: To simplify things you can generate one or more entities by passing the correspondings arguments in a single command, for example:

hermes-io-cli --observer="MyObserver" --context="MyContext"

result:

/contexts/MyContext.js
/observers/MyObserver.js

useObserver

By passing the hook argument a newly created folder named as 'hooks' is automatically generated. Within this folder, a brand-new observer hook file is generated, adopting the provided value as its designated name:

hermes-io-cli --hook="useCustom"

result:

/hooks/useCustom.js
import { useObserver, Context, Observer } from 'hermes-io';

export const CustomContext = new Context('CustomContext');
export const CustomObserver = new Context('CustomObserver');

export const UseCustom = () => {
const handleUseCustomNotification = (payload) => {
/* handle notification */
};
useObserver({
contexts: [CustomContext],
observer: CustomObserver,
listener: handleUseCustomNotification,
});
};

Note: Is posible to link existing observers or contexts to a newly generated useObserver if the name of any match with the name of the custom hook, for example:

hermes-io-cli --hook="useCustom" --context="Custom" --observer="Custom"

result:

/hooks/useCustom.js

/observers/Custom.js

/contexts/Custom.js
import { useObserver } from 'hermes-io';
import { Custom as ObserverCustom } from "../observers/Custom";
import { Custom as ContextCustom } from "../contexts/Custom";

export const UseCustom = () => {
const handleUseCustomNotification = (event) => {
/* handle notification */
console.log(event);
};
useObserver({
contexts: [ContextCustom],
observer: ObserverCustom,
listener: handleUseCustomNotification,
});
}

Root

By default the folders are generated using the current path as a base (typically at the root of the project), this can be changed by using the root argument:

hermes-io-cli --root="./output" --context="MyContext" --observer="MyObserver"

result:

/output/contexts/MyContext.js
/output/observers/MyObserver.js

Chrome extension

Chrome extension that allows inspect notifications emitted by hermes-io in a friendly UI

Install extension: here