0.0.2 • Published 6 months ago

hermes-io-cli v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Overview

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: contexts, hooks and observers.

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

Use observer

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 folder

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
0.0.2

6 months ago

0.0.1

6 months ago