UNPKG

@hairy/lnv

Version:
37 lines (34 loc) 1.01 kB
import {createRequire as __createRequire} from 'module';var require=__createRequire(import.meta.url); import { parseCommandString, replaceLiteralQuantity } from "./chunk-ANMSLEQF.js"; // src/run.ts import process from "node:process"; import spawn from "nano-spawn"; async function run(command, env) { if (Array.isArray(command)) command = command.join(" "); if (!command) throw new Error("Unable to run empty running script"); const mergedEnv = { ...process.env, ...env }; const options = { env: mergedEnv, stdio: "inherit", stderr: "inherit", stdin: "inherit", stdout: "inherit" }; const commands = command.split("&&").map((cmd) => cmd.trim()); for (let command2 of commands) { command2 = replaceLiteralQuantity(command2, mergedEnv); if (command2.includes(".sh") && !command2.startsWith("sh ")) { command2 = `sh ${command2}`; } const [cmd, ...args] = parseCommandString(command2); spawn(cmd, args, options); } } export { run };