MCPcopy
hub / github.com/upstash/jstack / execWithSpinner

Function execWithSpinner

cli/src/helpers/install-deps.ts:7–31  ·  view source on GitHub ↗
(
  projectDir: string,
  pkgManager: PackageManager,
  options: {
    args?: string[]
    stdout?: Options["stdout"]
    onDataHandle?: (spinner: Ora) => (data: Buffer) => void
  }
)

Source from the content-addressed store, hash-verified

5import ora, { type Ora } from "ora"
6
7const execWithSpinner = async (
8 projectDir: string,
9 pkgManager: PackageManager,
10 options: {
11 args?: string[]
12 stdout?: Options["stdout"]
13 onDataHandle?: (spinner: Ora) => (data: Buffer) => void
14 }
15) => {
16 const { onDataHandle, args = ["install"], stdout = "pipe" } = options
17
18 const spinner = ora(`Running ${pkgManager} install...`).start()
19 const subprocess = execa(pkgManager, args, { cwd: projectDir, stdout })
20
21 await new Promise<void>((res, rej) => {
22 if (onDataHandle) {
23 subprocess.stdout?.on("data", onDataHandle(spinner))
24 }
25
26 void subprocess.on("error", (e) => rej(e))
27 void subprocess.on("close", () => res())
28 })
29
30 return spinner
31}
32
33const runInstallCommand = async (pkgManager: PackageManager, projectDir: string): Promise<Ora | null> => {
34 switch (pkgManager) {

Callers 1

runInstallCommandFunction · 0.85

Calls 1

onMethod · 0.45

Tested by

no test coverage detected