@meru2802/nexus-modscript-composer
v2.0.10
Published
Compose multi-layer deployment scripts for NexusEPM agents (L0 → L1 → L2 pipeline)
Maintainers
Readme
@meru2802/nexus-modscript-composer
Compose multi-layer deployment scripts for NexusEPM agents. Takes individual L0 monitoring/collection scripts and produces a composed L1 collection script + L2 deployment wrapper (systemd service on Linux, Scheduled Task on Windows).
Install
npm install @meru2802/nexus-modscript-composerUsage
import { generateFinalScript } from "@meru2802/nexus-modscript-composer";
const l0Bodies = [tomcatScript, postgresqlScript]; // raw L0 script strings with metadata headers
const result = await generateFinalScript(l0Bodies, {
platform: "windows",
templateUrls: {
l1: "https://nexus-endpoint-desktop-app.s3.ap-south-1.amazonaws.com/l1-l2-templates/l1-windows.ps1.tmpl",
l2: "https://nexus-endpoint-desktop-app.s3.ap-south-1.amazonaws.com/l1-l2-templates/l2-windows.ps1.tmpl",
},
orgId: "acme-corp",
icebergEndpoint: "https://iceberg.example.com/api/v1/collect",
agentId: "agent-001",
authToken: "bearer-token",
bufferTime: "5m",
timeout: "10m",
});
console.log(result.l1Script); // composed L1 collection script
console.log(result.l2Script); // L2 deployment wrapper
console.log(result.modules); // ["tomcat", "postgresql"]Template URLs
| Platform | Layer | URL |
|----------|-------|-----|
| Linux | L1 | https://nexus-endpoint-desktop-app.s3.ap-south-1.amazonaws.com/l1-l2-templates/l1-linux.sh.tmpl |
| Linux | L2 | https://nexus-endpoint-desktop-app.s3.ap-south-1.amazonaws.com/l1-l2-templates/l2-linux.sh.tmpl |
| Windows | L1 | https://nexus-endpoint-desktop-app.s3.ap-south-1.amazonaws.com/l1-l2-templates/l1-windows.ps1.tmpl |
| Windows | L2 | https://nexus-endpoint-desktop-app.s3.ap-south-1.amazonaws.com/l1-l2-templates/l2-windows.ps1.tmpl |
generateFinalScript(l0ScriptBodies, options)
Parameters
l0ScriptBodies string[] -- Array of raw L0 script contents. Each string must include the full metadata header (# ==== NEXUS MODSCRIPT L0 ==== ... # ==== END METADATA ====) followed by the function body. All L0 scripts must target the same OS_FAMILY as the platform option.
options GenerateOptions:
| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| platform | "linux" \| "windows" | Yes | -- | Target OS. Must match the OS_FAMILY in all L0 scripts. |
| templateUrls | { l1: string, l2: string } | Yes | -- | URLs to fetch the L1 and L2 template files. See table above. |
| orgId | string | No | "test-client" | Organization ID baked into L1 for Iceberg payloads. |
| icebergEndpoint | string | No | "https://iceberg.example.com/api/v1/collect" | URL where L1 POSTs collected data. Written to the L2 env file. |
| agentId | string | No | "test-agent-001" | Agent identifier included in Iceberg payloads. |
| authToken | string | No | "test-bearer-token" | Bearer token for Iceberg API authentication. |
| bufferTime | string | No | "5m" | Wait time after L1 completes before next run. Accepts "30s", "5m", "1h". Linux: OnUnitInactiveSec. Windows: Start-Sleep in wrapper loop. |
| timeout | string | No | "10m" | Max L1 execution time before force-kill. Same format as bufferTime. Linux: TimeoutStartSec. Windows: WaitForExit(). |
| maxParallel | number | No | 5 | Max parallel L0 modules. Linux: background jobs. Windows: runspace pool size. |
| previousServiceId | string | No | "" | Service ID of a previous deployment to tear down before installing the new one. |
| writeToDisk | boolean | No | false | Write the composed scripts to timestamped files on disk. |
| outputDir | string | No | "./final-scripts" | Directory for writeToDisk output. Resolved relative to process.cwd(). |
Return Value
{
l1Script: string; // Composed L1 collection script (all L0 modules merged)
l2Script: string; // L2 deployment wrapper (installs L1 as systemd service or Scheduled Task)
platform: "linux" | "windows";
modules: string[]; // Names of L0 modules included, e.g. ["tomcat", "postgresql"]
l1Path?: string; // File path if writeToDisk was true
l2Path?: string; // File path if writeToDisk was true
}The function validates the composed scripts (structural checks, syntax via bash -n/shellcheck/pwsh, and a dry-run extraction test) before returning. It throws if validation fails.
