UNPKG

maests

Version:

An executable compiler for creating Maestro's yaml-flows with typescript.

24 lines (23 loc) 654 B
import { parse } from "yaml"; let nestLevel = 0, nestedCommands = []; const handleNest = (func, parseAsYaml) => { nestLevel++, func(); const out2 = nestedCommands[nestLevel - 1]; return nestedCommands[nestLevel - 1] = "", nestLevel--, parseAsYaml ? parse(out2) : out2; }; let out = ""; const resetOut = () => { out = ""; }, addOut = (command) => { nestLevel ? (nestedCommands[nestLevel - 1] || (nestedCommands[nestLevel - 1] = ""), nestedCommands[nestLevel - 1] += command) : out += command; }, getOut = () => { const currentOutput = out; return resetOut(), currentOutput; }; export { addOut, getOut, handleNest, out, resetOut };