-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathexec.js
More file actions
38 lines (33 loc) · 1.12 KB
/
exec.js
File metadata and controls
38 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { execa } from 'execa'
import kleur from 'kleur'
import { everyMonorepoProject, pipeOutput } from './utils.js'
/**
* @typedef {import("./types").GlobalOptions} GlobalOptions
* @typedef {import("./types").ExecOptions} ExecOptions
*/
export default {
/**
* @param {GlobalOptions & ExecOptions & { command: string }} ctx
*/
async run (ctx) {
const forwardArgs = ctx['--'] ? ctx['--'] : []
await everyMonorepoProject(async (project) => {
console.info('') // eslint-disable-line no-console
console.info(kleur.grey(`${project.manifest.name}:`), `> ${ctx.command}${forwardArgs.length > 0 ? ` ${forwardArgs.join(' ')}` : ''}`) // eslint-disable-line no-console
try {
const subprocess = execa(ctx.command, forwardArgs, {
cwd: project.dir
})
pipeOutput(subprocess, project.manifest.name, ctx.prefix)
await subprocess
} catch (/** @type {any} */ err) {
if (ctx.bail !== false) {
throw err
}
console.info(kleur.red(err.stack)) // eslint-disable-line no-console
}
}, {
concurrency: ctx.concurrency
})
}
}