-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.d.ts
160 lines (150 loc) · 4.37 KB
/
main.d.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import type { Transform } from 'node:stream'
import type { Options as ExecaOptions, ResultPromise } from 'execa'
// eslint-disable-next-line n/no-extraneous-import, @typescript-eslint/no-shadow
import type File from 'vinyl'
type NonStreamOptions = ExecaOptions &
Readonly<
Partial<{
/**
* Whether the `command` should be printed on the console.
*
* @default `debug` option's value
*/
echo: boolean
/**
* Whether both the `command` and its output (`stdout`/`stderr`) should be
* printed on the console instead of being returned in JavaScript.
*
* @default `true` for `task()` and `exec()`, `false` for `stream()`
*/
debug: boolean
}>
>
type StreamOptions = Omit<
NonStreamOptions,
'debug' | 'stdout' | 'stderr' | 'stdio' | 'all'
> &
Readonly<
Partial<{
/**
* Whether the command result should:
* - `replace` the file's contents
* - `save`: [be pushed](https://github.com/sindresorhus/execa#childprocessresult)
* to the `file.execa` array property
*
* @default 'replace'
*
* @example
* ```js
* import { pipeline } from 'node:stream/promises'
*
* import gulp from 'gulp'
* import { stream } from 'gulp-execa'
* import through from 'through2'
*
* export const task = () =>
* pipeline(
* gulp.src('*.js'),
* // Prints the number of lines of each file
* stream(({ path }) => `wc -l ${path}`, { result: 'save' }),
* through.obj((file, encoding, func) => {
* console.log(file.execa[0].stdout)
* func(null, file)
* }),
* )
* ```
*/
result: 'save' | 'replace'
/**
* Which output stream to use with `result: 'replace'`.
*
* @default 'stdout'
*
* @example
* ```js
* import { pipeline } from 'node:stream/promises'
*
* import gulp from 'gulp'
* import { stream } from 'gulp-execa'
* import through from 'through2'
*
* export const task = () =>
* pipeline(
* gulp.src('*.js'),
* // Prints the number of lines of each file, including `stderr`
* stream(({ path }) => `wc -l ${path}`, { result: 'replace', from: 'all' }),
* through.obj((file, encoding, func) => {
* console.log(file.contents.toString())
* func(null, file)
* }),
* )
* ```
*/
from: 'stdout' | 'stderr' | 'all'
/**
* How many commands to run in parallel at once.
*
* @default 100
*/
maxConcurrency: number
}>
>
export type Options = StreamOptions & NonStreamOptions
/**
* Executes `command`. The return value is both a promise and a
* [`child_process` instance](https://github.com/sindresorhus/execa#execacommand-options).
*
* The promise will be resolved with the
* [command result](https://github.com/sindresorhus/execa#childprocessresult).
* If the command failed, the promise will be rejected with a nice
* [error](https://github.com/sindresorhus/execa#childprocessresult).
* If the [`reject: false`](https://github.com/sindresorhus/execa#reject) option
* was used, the promise will be resolved with that error instead.
*
* @example
* ```js
* export const outdated = async () => {
* await exec('npm outdated')
* }
* ```
*/
export function exec<CallOptions extends NonStreamOptions = object>(
command: string,
options?: CallOptions,
): ResultPromise<CallOptions>
/**
* Returns a Gulp task that executes `command`.
*
* @example
* ```js
* export const audit = task('npm audit')
* ```
*/
export function task<CallOptions extends NonStreamOptions = object>(
command: string,
options?: CallOptions,
): () => ResultPromise<CallOptions>
/**
* Returns a stream that executes a `command` on each input file.
*
* @example
* ```js
* import { pipeline } from 'node:stream/promises'
*
* import gulp from 'gulp'
* import { stream } from 'gulp-execa'
*
* export const sort = () =>
* pipeline(
* gulp.src('*.txt'),
* stream(({ path }) => `sort ${path}`),
* gulp.dest('sorted'),
* )
* ```
*/
export function stream(
getCommand: (
file: File,
) => string | (Options & { command: string }) | undefined,
options?: StreamOptions,
): Transform