UNPKG

@tsed/cli-core

Version:
35 lines (34 loc) 1.04 kB
import { injectable } from "@tsed/di"; import { execa, execaSync } from "execa"; import { filter, mergeWith } from "rxjs/operators"; // @ts-ignore import split from "split"; import { streamToObservable } from "../utils/streamToObservable.js"; export class CliExeca { constructor() { this.raw = execa; this.rawSync = execaSync; } /** * * @param cmd * @param args * @param opts */ run(cmd, args, opts) { const cp = this.raw(cmd, args, opts); const stdout = streamToObservable(cp.stdout.pipe(split()), { await: cp }); const stderr = streamToObservable(cp.stderr.pipe(split()), { await: cp }); return stdout.pipe(mergeWith(stderr)).pipe(filter(Boolean)); } runSync(cmd, args, opts) { return this.rawSync(cmd, args, opts); } async getAsync(cmd, args, opts) { return (await this.raw(cmd, args, opts)).stdout; } get(cmd, args, opts) { return this.rawSync(cmd, args, opts).stdout; } } injectable(CliExeca);