forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shelljs.d.ts
536 lines (461 loc) · 27.4 KB
/
shelljs.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// Type definitions for ShellJS v0.3.0
// Project: http://shelljs.org
// Definitions by: Niklas Mollenhauer <https://github.com/nikeee>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference path="../node/node.d.ts"/>
declare module "shelljs"
{
import child = require("child_process");
/**
* Changes to directory dir for the duration of the script
* @param {string} dir Directory to change in.
*/
export function cd(dir: string): void;
/**
* Returns the current directory.
* @return {string} The current directory.
*/
export function pwd(): string;
/**
* Returns array of files in the given path, or in current directory if no path provided.
* @param {string[]} ...paths Paths to search.
* @return {string[]} An array of files in the given path(s).
*/
export function ls(...paths: string[]): string[];
/**
* Returns array of files in the given path, or in current directory if no path provided.
* @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
* @param {string[]} ...paths Paths to search.
* @return {string[]} An array of files in the given path(s).
*/
export function ls(options: string, ...paths: string[]): string[];
/**
* Returns array of files in the given path, or in current directory if no path provided.
* @param {string[]} paths Paths to search.
* @return {string[]} An array of files in the given path(s).
*/
export function ls(paths: string[]): string[];
/**
* Returns array of files in the given path, or in current directory if no path provided.
* @param {string} options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..)
* @param {string[]} paths Paths to search.
* @return {string[]} An array of files in the given path(s).
*/
export function ls(options: string, paths: string[]): string[];
/**
* Returns array of all files (however deep) in the given paths.
* @param {string[]} ...path The path(s) to search.
* @return {string[]} An array of all files (however deep) in the given path(s).
*/
export function find(...path: string[]): string[];
/**
* Returns array of all files (however deep) in the given paths.
* @param {string[]} path The path(s) to search.
* @return {string[]} An array of all files (however deep) in the given path(s).
*/
export function find(path: string[]): string[];
/**
* Copies files. The wildcard * is accepted.
* @param {string} source The source.
* @param {string} dest The destination.
*/
export function cp(source: string, dest: string): void;
/**
* Copies files. The wildcard * is accepted.
* @param {string[]} source The source.
* @param {string} dest The destination.
*/
export function cp(source: string[], dest: string): void;
/**
* Copies files. The wildcard * is accepted.
* @param {string} options Available options: -f (force), -r, -R (recursive)
* @param {strin]} source The source.
* @param {string} dest The destination.
*/
export function cp(options: string, source: string, dest: string): void;
/**
* Copies files. The wildcard * is accepted.
* @param {string} options Available options: -f (force), -r, -R (recursive)
* @param {string[]} source The source.
* @param {string} dest The destination.
*/
export function cp(options: string, source: string[], dest: string): void;
/**
* Removes files. The wildcard * is accepted.
* @param {string[]} ...files Files to remove.
*/
export function rm(...files: string[]): void;
/**
* Removes files. The wildcard * is accepted.
* @param {string[]} files Files to remove.
*/
export function rm(files: string[]): void;
/**
* Removes files. The wildcard * is accepted.
* @param {string} options Available options: -f (force), -r, -R (recursive)
* @param {string[]} ...files Files to remove.
*/
export function rm(options: string, ...files: string[]): void;
/**
* Removes files. The wildcard * is accepted.
* @param {string} options Available options: -f (force), -r, -R (recursive)
* @param {string[]} ...files Files to remove.
*/
export function rm(options: string, files: string[]): void;
/**
* Moves files. The wildcard * is accepted.
* @param {string} source The source.
* @param {string} dest The destination.
*/
export function mv(source: string, dest: string): void;
/**
* Moves files. The wildcard * is accepted.
* @param {string[]} source The source.
* @param {string} dest The destination.
*/
export function mv(source: string[], dest: string): void;
/**
* Creates directories.
* @param {string[]} ...dir Directories to create.
*/
export function mkdir(...dir: string[]): void;
/**
* Creates directories.
* @param {string[]} dir Directories to create.
*/
export function mkdir(dir: string[]): void;
/**
* Creates directories.
* @param {string} options Available options: p (full paths, will create intermediate dirs if necessary)
* @param {string[]} ...dir The directories to create.
*/
export function mkdir(options: string, ...dir: string[]): void;
/**
* Creates directories.
* @param {string} options Available options: p (full paths, will create intermediate dirs if necessary)
* @param {string[]} dir The directories to create.
*/
export function mkdir(options: string, dir: string[]): void;
/**
* Evaluates expression using the available primaries and returns corresponding value.
* @param {string} option '-b': true if path is a block device; '-c': true if path is a character device; '-d': true if path is a directory; '-e': true if path exists; '-f': true if path is a regular file; '-L': true if path is a symboilc link; '-p': true if path is a pipe (FIFO); '-S': true if path is a socket
* @param {string} path The path.
* @return {boolean} See option parameter.
*/
export function test(option: string, path: string): boolean;
/**
* Returns a string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). Wildcard * accepted.
* @param {string[]} ...files Files to use.
* @return {string} A string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file).
*/
export function cat(...files: string[]): string;
/**
* Returns a string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). Wildcard * accepted.
* @param {string[]} files Files to use.
* @return {string} A string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file).
*/
export function cat(files: string[]): string;
// Does not work yet.
export interface String
{
/**
* Analogous to the redirection operator > in Unix, but works with JavaScript strings (such as those returned by cat, grep, etc). Like Unix redirections, to() will overwrite any existing file!
* @param {string} file The file to use.
*/
to(file: string): void;
/**
* Analogous to the redirect-and-append operator >> in Unix, but works with JavaScript strings (such as those returned by cat, grep, etc).
* @param {string} file The file to append to.
*/
toEnd(file: string): void;
}
/**
* Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement.
* @param {RegExp} searchRegex The regular expression to use for search.
* @param {string} replacement The replacement.
* @param {string} file The file to process.
* @return {string} The new string after replacement.
*/
export function sed(searchRegex: RegExp, replacement: string, file: string): string;
/**
* Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement.
* @param {string} searchRegex The regular expression to use for search.
* @param {string} replacement The replacement.
* @param {string} file The file to process.
* @return {string} The new string after replacement.
*/
export function sed(searchRegex: string, replacement: string, file: string): string;
/**
* Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement.
* @param {string} options Available options: -i (Replace contents of 'file' in-place. Note that no backups will be created!)
* @param {RegExp} searchRegex The regular expression to use for search.
* @param {string} replacement The replacement.
* @param {string} file The file to process.
* @return {string} The new string after replacement.
*/
export function sed(options: string, searchRegex: RegExp, replacement: string, file: string): string;
/**
* Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement.
* @param {string} options Available options: -i (Replace contents of 'file' in-place. Note that no backups will be created!)
* @param {string} searchRegex The regular expression to use for search.
* @param {string} replacement The replacement.
* @param {string} file The file to process.
* @return {string} The new string after replacement.
*/
export function sed(options: string, searchRegex: string, replacement: string, file: string): string;
/**
* Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted.
* @param {RegExp} regex_filter The regular expression to use.
* @param {string[]} ...files The files to process.
* @return {string} Returns a string containing all lines of the file that match the given regex_filter.
*/
export function grep(regex_filter: RegExp, ...files: string[]): string;
/**
* Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted.
* @param {RegExp} regex_filter The regular expression to use.
* @param {string[]} ...files The files to process.
* @return {string} Returns a string containing all lines of the file that match the given regex_filter.
*/
export function grep(regex_filter: RegExp, files: string[]): string;
/**
* Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted.
* @param {string} options Available options: -v (Inverse the sense of the regex and print the lines not matching the criteria.)
* @param {string} regex_filter The regular expression to use.
* @param {string[]} ...files The files to process.
* @return {string} Returns a string containing all lines of the file that match the given regex_filter.
*/
export function grep(options: string, regex_filter: string, ...files: string[]): string;
/**
* Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted.
* @param {string} options Available options: -v (Inverse the sense of the regex and print the lines not matching the criteria.)
* @param {string} regex_filter The regular expression to use.
* @param {string[]} files The files to process.
* @return {string} Returns a string containing all lines of the file that match the given regex_filter.
*/
export function grep(options: string, regex_filter: string, files: string[]): string;
/**
* Searches for command in the system's PATH. On Windows looks for .exe, .cmd, and .bat extensions.
* @param {string} command The command to search for.
* @return {string} Returns string containing the absolute path to the command.
*/
export function which(command: string): string;
/**
* Prints string to stdout, and returns string with additional utility methods like .to().
* @param {string[]} ...text The text to print.
* @return {string} Returns the string that was passed as argument.
*/
export function echo(...text: string[]): string;
/**
* Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
* @param {"+N"} dir Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
* @return {string[]} Returns an array of paths in the stack.
*/
export function pushd(dir: "+N"): string[];
/**
* Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
* @param {"-N"} dir Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
* @return {string[]} Returns an array of paths in the stack.
*/
export function pushd(dir: "-N"): string[];
/**
* Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
* @param {string} dir Makes the current working directory be the top of the stack, and then executes the equivalent of cd dir.
* @return {string[]} Returns an array of paths in the stack.
*/
export function pushd(dir: string): string[];
/**
* Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
* @param {string} options Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated)
* @param {"+N"} dir Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
* @return {string[]} Returns an array of paths in the stack.
*/
export function pushd(options: string, dir: "+N"): string[];
/**
* Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
* @param {string} options Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated)
* @param {"-N"} dir Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
* @return {string[]} Returns an array of paths in the stack.
*/
export function pushd(options: string, dir: "-N"): string[];
/**
* Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
* @param {string} options Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated)
* @param {string} dir Makes the current working directory be the top of the stack, and then executes the equivalent of cd dir.
* @return {string[]} Returns an array of paths in the stack.
*/
export function pushd(options: string, dir: string): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @param {"+N"} dir Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(dir: "+N"): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @param {"-N"} dir Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(dir: "-N"): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @param {string} dir You can only use -N and +N.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(dir: string): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @param {string} options Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated)
* @param {"+N"} dir Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(options: string, dir: "+N"): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @param {string} options Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated)
* @param {"-N"} dir Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(options: string, dir: "-N"): string[];
/**
* When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
* @param {string} options Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated)
* @param {string} dir You can only use -N and +N.
* @return {string[]} Returns an array of paths in the stack.
*/
export function popd(options: string, dir: string): string[];
/**
* Clears the directory stack by deleting all of the elements.
* @param {"-c"} options Clears the directory stack by deleting all of the elements.
* @return {string[]} Returns an array of paths in the stack, or a single path if +N or -N was specified.
*/
export function dirs(options: "-c"): string[];
/**
* Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.
* @param {"+N"} options Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero.
* @return {string[]} Returns an array of paths in the stack, or a single path if +N or -N was specified.
*/
export function dirs(options: "+N"): string;
/**
* Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.
* @param {"-N"} options Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero.
* @return {string[]} Returns an array of paths in the stack, or a single path if +N or -N was specified.
*/
export function dirs(options: "-N"): string;
/**
* Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.
* @param {string} options Available options: -c, -N, +N. You can only use those.
* @return {any} Returns an array of paths in the stack, or a single path if +N or -N was specified.
*/
export function dirs(options: string): any;
/**
* Links source to dest. Use -f to force the link, should dest already exist.
* @param {string} source The source.
* @param {string} dest The destination.
*/
export function ln(source: string, dest: string): void;
/**
* Links source to dest. Use -f to force the link, should dest already exist.
* @param {string} options Available options: s (symlink), f (force)
* @param {string} source The source.
* @param {string} dest The destination.
*/
export function ln(options: string, source: string, dest: string): void;
/**
* Exits the current process with the given exit code.
* @param {number} code The exit code.
*/
export function exit(code: number): void;
/**
* Object containing environment variables (both getter and setter). Shortcut to process.env.
*/
export var env: { [key: string]: string };
/**
* Executes the given command synchronously.
* @param {string} command The command to execute.
* @return {ExecOutputReturnValue} Returns an object containing the return code and output as string.
*/
export function exec(command: string): ExecOutputReturnValue;
/**
* Executes the given command synchronously.
* @param {string} command The command to execute.
* @param {ExecOptions} options Silence and synchronous options.
* @return {ExecOutputReturnValue | child.ChildProcess} Returns an object containing the return code and output as string, or if {async:true} was passed, a ChildProcess.
*/
export function exec(command: string, options: ExecOptions): ExecOutputReturnValue | child.ChildProcess;
/**
* Executes the given command synchronously.
* @param {string} command The command to execute.
* @param {ExecOptions} options Silence and synchronous options.
* @param {ExecCallback} callback Receives code and output asynchronously.
*/
export function exec(command: string, options: ExecOptions, callback: ExecCallback): child.ChildProcess;
/**
* Executes the given command synchronously.
* @param {string} command The command to execute.
* @param {ExecCallback} callback Receives code and output asynchronously.
*/
export function exec(command: string, callback: ExecCallback): child.ChildProcess;
export interface ExecCallback {
(code: number, output: string, error?: string): any;
}
export interface ExecOptions {
silent?: boolean;
async?: boolean;
}
export interface ExecOutputReturnValue
{
code: number;
output: string;
}
/**
* Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions:
* - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
* - There is no "quiet" option since default behavior is to run silent.
* @param {number} octalMode The access mode. Octal.
* @param {string} file The file to use.
*/
export function chmod(octalMode: number, file: string): void;
/**
* Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions:
* - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
* - There is no "quiet" option since default behavior is to run silent.
* @param {string} mode The access mode. Can be an octal string or a symbolic mode string.
* @param {string} file The file to use.
*/
export function chmod(mode: string, file: string): void;
// Non-Unix commands
/**
* Searches and returns string containing a writeable, platform-dependent temporary directory. Follows Python's tempfile algorithm.
* @return {string} The temp file path.
*/
export function tempdir(): string;
/**
* Tests if error occurred in the last command.
* @return {string} Returns null if no error occurred, otherwise returns string explaining the error
*/
export function error(): string;
// Configuration
interface ShellConfig
{
/**
* Suppresses all command output if true, except for echo() calls. Default is false.
* @type {boolean}
*/
silent: boolean;
/**
* If true the script will die on errors. Default is false.
* @type {boolean}
*/
fatal: boolean;
}
/**
* The shelljs configuration.
* @type {ShellConfig}
*/
export var config: ShellConfig;
}