SOMOD Extensions


Extend the working of the SOMOD toolset using the extensions. An Extension is a SOMOD module having an extension.ts file at the root of the project.

Extension file structure

project-root | +-- node_modules --+ | +-- module-a | | +-- build/ | FROM DEPENDENCIES | +-- extension.js | | --+ | | +-- build/ --+ | +-- extension.js | BUILD OUTPUT | --+ | +-- extension.ts -- SOURCE

During the build stage, SOMOD compiles extension.ts into build/extension.js. While preparing, SOMOD loads and applies extensions from all the installed modules.

Content of Extension

Provide the following named exports from the extension.ts file to modify the behavior of the SOMOD tool. Each named export is optional.

Hooks

Hooks are the custom functions called during the build and preparation phase.

  • prebuild

    import { IContext } from "somod"; export const prebuild = async (context: IContext) => { // do pre-build actions };
    • prebuild hooks are called after the validation and before the build tasks during the somod build command.
    • prebuild hooks are called in the order of module dependency from parent to child. For example, if extension A depends on extension B, prebuild of A is called before prebuild of B.
  • build

    import { IContext } from "somod"; export const build = async (context: IContext) => { // do build actions };
    • build hooks are called after the build tasks during the somod build command.
    • build hooks are called in the order of module dependency from child to parent. For example, if extension A depends on extension B, the build hook of B is called before the build hook of A.
  • preprepare

    import { IContext } from "somod"; export const preprepare = async (context: IContext) => { // do pre-prepare actions };
    • preprepare hooks are called before the prepare tasks during the somod prepare command.
    • preprepare hooks are called in the order of module dependency from parent to child. For example, if extension A depends on extension B, preprepare of A is called before preprepare of B.
  • prepare

    import { IContext } from "somod"; export const prepare = async (context: IContext) => { // do prepare actions };
    • prepare hooks are called after the prepare tasks during the somod prepare command.
    • prepare hooks are called in the order of module dependency from child to parent. For example, if extension A depends on extension B, the prepare hook of B is called before the prepare hook of A.

Namespaces

Extensions can provide namespaces using namespaceLoader

  • namespaceLoader

    import { NamespaceLoader } from "somod"; export const namespaceLoader: NamespaceLoader = async (module, context) => { // return namespaces for the provided module };

Keywords

Extend the parsing of ui/config.yaml and serverless/template.yaml using extension keywords.

  • uiConfigKeywords

    import { KeywordDefinition } from "somod"; export const uiConfigKeywords: KeywordDefinition[] = [ // keywords with validator and processor functions ];
  • serverlessTemplateKeywords

    import { KeywordDefinition } from "somod"; export const serverlessTemplateKeywords: KeywordDefinition[] = [ // keywords with validator and processor functions ];

Serverless Functions

Extend the Serverless functions with the following properties from the extension.

  • functionLayers

    Defines the layers to be applied to serverless functions from all installed modules

    export const functionLayers: string[] = [ // Resource Ids of the layers declared in serverless/template.yaml of this project ];
  • functionMiddlewares

    Defines the list of middleware to be applied to serverless functions from all installed modules

    export const functionMiddlewares: string[] = [ // Resource Ids of the middlewares declared in serverless/template.yaml of this project ];

Now we have understood the main concepts of SOMOD, let us explore the SOMOD CLI in the next chapter

Does this page need improvements?
Edit This Page in GitHub
Did this page help you?
Provide feedback in the GitHub Discussion Page
Need More help?

Write an email to opensource@sodaru.com

This documentation is built using
Developed and Maintained By
Sodaru Technologies
https://sodaru.com
© 2023