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.
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.
Provide the following named exports from the extension.ts
file to modify the behavior of the SOMOD tool. Each named export is optional.
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 };
somod build
command.build
import { IContext } from "somod"; export const build = async (context: IContext) => { // do build actions };
somod build
command.preprepare
import { IContext } from "somod"; export const preprepare = async (context: IContext) => { // do pre-prepare actions };
somod prepare
command.prepare
import { IContext } from "somod"; export const prepare = async (context: IContext) => { // do prepare actions };
somod prepare
command.Extensions can provide namespaces using namespaceLoader
namespaceLoader
import { NamespaceLoader } from "somod"; export const namespaceLoader: NamespaceLoader = async (module, context) => { // return namespaces for the provided module };
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 ];
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
Write an email to opensource@sodaru.com