UNPKG

@enspirit/emb

Version:

A replacement for our Makefile-for-monorepos

47 lines (46 loc) 1.41 kB
import { execa } from 'execa'; import * as z from 'zod'; import { AbstractOperation } from '../../../operations/index.js'; /** * https://docs.docker.com/reference/api/engine/version/v1.37/#tag/Exec/operation/ContainerExec */ const schema = z.object({ env: z .record(z.string(), z.string()) .optional() .describe('A list of environment variables in the form'), script: z.string().describe('Command to run, as a string'), interactive: z .boolean() .describe('Interactive command') .default(false) .optional(), workingDir: z .string() .optional() .describe('The working directory for the exec process inside the container'), }); export class ExecuteLocalCommandOperation extends AbstractOperation { out; constructor(out) { super(schema); this.out = out; } async _run(input) { const proc = input.interactive ? execa(input.script, { cwd: input.workingDir, shell: true, env: input.env, stdin: 'inherit', }) : execa(input.script, { all: true, cwd: input.workingDir, shell: true, env: input.env, }); proc.all?.pipe(this.out || process.stdout); return proc.all || proc.stdout; } }