-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinteractive-runner.mjs
More file actions
72 lines (65 loc) · 1.85 KB
/
interactive-runner.mjs
File metadata and controls
72 lines (65 loc) · 1.85 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* @fileoverview Interactive runner for commands with ctrl+o toggle.
* Standardized across all socket-* repositories.
*/
import process from 'node:process'
import { runWithMask } from '@socketsecurity/lib/stdio/mask'
/**
* Run a command with interactive output control.
* Standard experience across all socket-* repos.
*
* @param {string} command - Command to run
* @param {string[]} args - Command arguments
* @param {object} options - Options
* @param {string} options.message - Progress message
* @param {string} options.toggleText - Text after "ctrl+o" (default: "to see output")
* @param {boolean} options.showOnError - Show output on error (default: true)
* @param {boolean} options.verbose - Start in verbose mode (default: false)
* @returns {Promise<number>} Exit code
*/
export async function runWithOutput(command, args = [], options = {}) {
const {
cwd = process.cwd(),
env = process.env,
message = 'Running',
toggleText = 'to see output',
verbose = false,
} = options
return runWithMask(command, args, {
cwd,
env,
message,
showOutput: verbose,
toggleText,
})
}
/**
* Standard test runner with interactive output.
*/
export async function runTests(command, args, options = {}) {
return runWithOutput(command, args, {
message: 'Running tests',
toggleText: 'to see test output',
...options,
})
}
/**
* Standard lint runner with interactive output.
*/
export async function runLint(command, args, options = {}) {
return runWithOutput(command, args, {
message: 'Running linter',
toggleText: 'to see lint results',
...options,
})
}
/**
* Standard build runner with interactive output.
*/
export async function runBuild(command, args, options = {}) {
return runWithOutput(command, args, {
message: 'Building',
toggleText: 'to see build output',
...options,
})
}