1 | /// <reference types="node"/>
|
2 |
|
3 | import child = require("child_process");
|
4 | import glob = require("glob");
|
5 |
|
6 | /**
|
7 | * Changes the current working directory dir for the duration of the script.
|
8 | * Changes to the home directory if no argument is supplied.
|
9 | *
|
10 | * @param dir Directory to change to.
|
11 | * @return Object with shell exit code, stderr and stdout.
|
12 | */
|
13 | export function cd(dir?: string): ShellString;
|
14 |
|
15 | /**
|
16 | * Returns the current directory.
|
17 | * @return The current directory.
|
18 | */
|
19 | export function pwd(): ShellString;
|
20 |
|
21 | export interface ListFunction {
|
22 | /**
|
23 | * Returns array of files in the given path, or in current directory if no path provided.
|
24 | *
|
25 | * @param options Available options:
|
26 | * - `-R`: recursive
|
27 | * - `-A`: all files (include files beginning with ., except for . and ..)
|
28 | * - `-L`: follow symlinks
|
29 | * - `-d`: list directories themselves, not their contents
|
30 | * - `-l`: list objects representing each file, each with fields containing
|
31 | * `ls -l` output fields. See fs.Stats for more info
|
32 | * @param paths Paths to search.
|
33 | * @return An array of files in the given path(s).
|
34 | */
|
35 | (options: string, paths: string[]): ShellArray;
|
36 | (options: string, ...paths: string[]): ShellArray;
|
37 |
|
38 | /**
|
39 | * Returns array of files in the given path, or in current directory if no path provided.
|
40 | *
|
41 | * @param paths Paths to search.
|
42 | * @return An array of files in the given path(s).
|
43 | */
|
44 | (paths: string[]): ShellArray;
|
45 | (...paths: string[]): ShellArray;
|
46 | }
|
47 |
|
48 | /**
|
49 | * Returns array of files in the given path, or in current directory if no path provided.
|
50 | *
|
51 | * @param options Available options:
|
52 | * - `-R`: recursive
|
53 | * - `-A`: all files (include files beginning with ., except for . and ..)
|
54 | * - `-L`: follow symlinks
|
55 | * - `-d`: list directories themselves, not their contents
|
56 | * - `-l`: list objects representing each file, each with fields containing
|
57 | * `ls -l` output fields. See fs.Stats for more info
|
58 | * @param paths Paths to search.
|
59 | * @return An array of files in the given path(s).
|
60 | */
|
61 | export const ls: ListFunction;
|
62 |
|
63 | export interface FindFunction {
|
64 | /**
|
65 | * Returns array of all files (however deep) in the given paths.
|
66 | *
|
67 | * @param path The path(s) to search.
|
68 | * @return An array of all files (however deep) in the given path(s).
|
69 | */
|
70 | (path: string[]): ShellArray;
|
71 | (...path: string[]): ShellArray;
|
72 | }
|
73 |
|
74 | /**
|
75 | * Returns array of all files (however deep) in the given paths.
|
76 | *
|
77 | * @param path The path(s) to search.
|
78 | * @return An array of all files (however deep) in the given path(s).
|
79 | */
|
80 | export const find: FindFunction;
|
81 |
|
82 | export interface CopyFunction {
|
83 | /**
|
84 | * Copies files. The wildcard `*` is accepted.
|
85 | *
|
86 | * @param options Available options:
|
87 | * - `-f`: force (default behavior)
|
88 | * - `-n`: no-clobber
|
89 | * - `-u`: only copy if source is newer than dest
|
90 | * - `-r`, `-R`: recursive
|
91 | * - `-L`: follow symlinks
|
92 | * - `-P`: don't follow symlinks
|
93 | * @param source The source.
|
94 | * @param dest The destination.
|
95 | * @return Object with shell exit code, stderr and stdout.
|
96 | */
|
97 | (options: string, source: string | string[], dest: string): ShellString;
|
98 |
|
99 | /**
|
100 | * Copies files. The wildcard `*` is accepted.
|
101 | *
|
102 | * @param source The source.
|
103 | * @param dest The destination.
|
104 | * @return Object with shell exit code, stderr and stdout.
|
105 | */
|
106 | (source: string | string[], dest: string): ShellString;
|
107 | }
|
108 |
|
109 | /**
|
110 | * Copies files. The wildcard `*` is accepted.
|
111 | *
|
112 | * @param options Available options:
|
113 | * - `-f`: force (default behavior)
|
114 | * - `-n`: no-clobber
|
115 | * - `-u`: only copy if source is newer than dest
|
116 | * - `-r`, -R: recursive
|
117 | * - `-L`: follow symlinks
|
118 | * - `-P`: don't follow symlinks
|
119 | * @param source The source.
|
120 | * @param dest The destination.
|
121 | * @return Object with shell exit code, stderr and stdout.
|
122 | */
|
123 | export const cp: CopyFunction;
|
124 |
|
125 | export interface RemoveFunction {
|
126 | /**
|
127 | * Removes files. The wildcard `*` is accepted.
|
128 | *
|
129 | * @param options Available options:
|
130 | * - `-f`: force
|
131 | * - `-r`, `-R`: recursive
|
132 | * @param files Files to remove.
|
133 | * @return Object with shell exit code, stderr and stdout.
|
134 | */
|
135 | (options: string, files: string[]): ShellString;
|
136 | (options: string, ...files: string[]): ShellString;
|
137 |
|
138 | /**
|
139 | * Removes files. The wildcard `*` is accepted.
|
140 | *
|
141 | * @param files Files to remove.
|
142 | * @return Object with shell exit code, stderr and stdout.
|
143 | */
|
144 | (files: string[]): ShellString;
|
145 | (...files: string[]): ShellString;
|
146 | }
|
147 |
|
148 | /**
|
149 | * Removes files. The wildcard `*` is accepted.
|
150 | *
|
151 | * @param options Available options:
|
152 | * - `-f` (force),
|
153 | * - `-r`, `-R` (recursive)
|
154 | * @param files Files to remove.
|
155 | * @return Object with shell exit code, stderr and stdout.
|
156 | */
|
157 | export const rm: RemoveFunction;
|
158 |
|
159 | export interface MoveFunction {
|
160 | /**
|
161 | * Moves files. The wildcard `*` is accepted.
|
162 | *
|
163 | * @param options Available options:
|
164 | * - `-f`: force (default behavior)
|
165 | * - `-n`: no-clobber
|
166 | * @param source The source.
|
167 | * @param dest The destination.
|
168 | * @return Object with shell exit code, stderr and stdout.
|
169 | */
|
170 | (options: string, source: string | string[], dest: string): ShellString;
|
171 |
|
172 | /**
|
173 | * Moves files. The wildcard `*` is accepted.
|
174 | *
|
175 | * @param source The source.
|
176 | * @param dest The destination.
|
177 | * @return Object with shell exit code, stderr and stdout.
|
178 | */
|
179 | (source: string | string[], dest: string): ShellString;
|
180 | }
|
181 |
|
182 | /**
|
183 | * Moves files. The wildcard `*` is accepted.
|
184 | *
|
185 | * @param options Available options:
|
186 | * - `-f`: force (default behavior)
|
187 | * - `-n`: no-clobber
|
188 | * @param source The source.
|
189 | * @param dest The destination.
|
190 | * @return Object with shell exit code, stderr and stdout.
|
191 | */
|
192 | export const mv: MoveFunction;
|
193 |
|
194 | export interface MkdirFunction {
|
195 | /**
|
196 | * Creates directories.
|
197 | *
|
198 | * @param options Available options:
|
199 | * - `-p`: full paths, will create intermediate dirs if necessary
|
200 | * @param dir The directories to create.
|
201 | * @return Object with shell exit code, stderr and stdout.
|
202 | */
|
203 | (options: string, dir: string[]): ShellString;
|
204 | (options: string, ...dir: string[]): ShellString;
|
205 |
|
206 | /**
|
207 | * Creates directories.
|
208 | *
|
209 | * @param dir Directories to create.
|
210 | * @return Object with shell exit code, stderr and stdout.
|
211 | */
|
212 | (dir: string[]): ShellString;
|
213 | (...dir: string[]): ShellString;
|
214 | }
|
215 |
|
216 | /**
|
217 | * Creates directories.
|
218 | *
|
219 | * @param options Available options:
|
220 | * - `-p`: full paths, will create intermediate dirs if necessary
|
221 | * @param dir The directories to create.
|
222 | * @return Object with shell exit code, stderr and stdout.
|
223 | */
|
224 | export const mkdir: MkdirFunction;
|
225 |
|
226 | /**
|
227 | * Evaluates expression using the available primaries and returns corresponding value.
|
228 | *
|
229 | * @param option Valid options:
|
230 | * - `-b`: true if path is a block device;
|
231 | * - `-c`: true if path is a character device;
|
232 | * - `-d`: true if path is a directory;
|
233 | * - `-e`: true if path exists;
|
234 | * - `-f`: true if path is a regular file;
|
235 | * - `-L`: true if path is a symbolic link;
|
236 | * - `-p`: true if path is a pipe (FIFO);
|
237 | * - `-S`: true if path is a socket
|
238 | * @param path The path.
|
239 | * @return See option parameter.
|
240 | */
|
241 | export function test(option: TestOptions, path: string): boolean;
|
242 |
|
243 | export type TestOptions = "-b" | "-c" | "-d" | "-e" | "-f" | "-L" | "-p" | "-S";
|
244 |
|
245 | export interface CatFunction {
|
246 | /**
|
247 | * Returns a string containing the given file, or a concatenated string
|
248 | * containing the files if more than one file is given (a new line character
|
249 | * is introduced between each file).
|
250 | *
|
251 | * @param files Files to use. Wildcard `*` accepted.
|
252 | * @return A string containing the given file, or a concatenated string
|
253 | * containing the files if more than one file is given
|
254 | * (a new line character is introduced between each file).
|
255 | */
|
256 | (files: string[]): ShellString;
|
257 | (...files: string[]): ShellString;
|
258 | }
|
259 |
|
260 | /**
|
261 | * Returns a string containing the given file, or a concatenated string
|
262 | * containing the files if more than one file is given (a new line character
|
263 | * is introduced between each file).
|
264 | *
|
265 | * @param files Files to use. Wildcard `*` accepted.
|
266 | * @return A string containing the given file, or a concatenated string
|
267 | * containing the files if more than one file is given
|
268 | * (a new line character is introduced between each file).
|
269 | */
|
270 | export const cat: CatFunction;
|
271 |
|
272 | export interface SedFunction {
|
273 | /**
|
274 | * Reads an input string from file and performs a JavaScript `replace()`
|
275 | * on the input using the given search regex and replacement string or function.
|
276 | *
|
277 | * @param options Available options:
|
278 | * - `-i`: Replace contents of 'file' in-place. Note that no backups will be created!
|
279 | * @param searchRegex The regular expression to use for search.
|
280 | * @param replacement The replacement.
|
281 | * @param files The files to process.
|
282 | * @return The new string after replacement.
|
283 | */
|
284 | (options: string, searchRegex: string | RegExp, replacement: string, files: string[]): ShellString;
|
285 | (options: string, searchRegex: string | RegExp, replacement: string, ...files: string[]): ShellString;
|
286 |
|
287 | /**
|
288 | * Reads an input string from file and performs a JavaScript `replace()`
|
289 | * on the input using the given search regex and replacement string or function.
|
290 | *
|
291 | * @param searchRegex The regular expression to use for search.
|
292 | * @param replacement The replacement.
|
293 | * @param files The files to process.
|
294 | * @return The new string after replacement.
|
295 | */
|
296 | (searchRegex: string | RegExp, replacement: string, files: string[]): ShellString;
|
297 | (searchRegex: string | RegExp, replacement: string, ...files: string[]): ShellString;
|
298 | }
|
299 |
|
300 | /**
|
301 | * Reads an input string from file and performs a JavaScript `replace()`
|
302 | * on the input using the given search regex and replacement string or function.
|
303 | *
|
304 | * @param options Available options:
|
305 | * - `-i`: Replace contents of 'file' in-place. Note that no backups will be created!
|
306 | * @param searchRegex The regular expression to use for search.
|
307 | * @param replacement The replacement.
|
308 | * @param files The files to process.
|
309 | * @return The new string after replacement.
|
310 | */
|
311 | export const sed: SedFunction;
|
312 |
|
313 | export interface GrepFunction {
|
314 | /**
|
315 | * Reads input string from given files and returns a string containing all lines
|
316 | * of the file that match the given `regex_filter`. Wildcard `*` accepted.
|
317 | *
|
318 | * @param options Available options:
|
319 | * - `-v`: Inverse the sense of the regex and print
|
320 | * the lines not matching the criteria.
|
321 | * - `-l`: Print only filenames of matching files
|
322 | * @param regex_filter The regular expression to use.
|
323 | * @param files The files to process.
|
324 | * @return Returns a string containing all lines of the file that match the given regex_filter.
|
325 | */
|
326 | (options: string, regex_filter: string | RegExp, files: string[]): ShellString;
|
327 | (options: string, regex_filter: string | RegExp, ...files: string[]): ShellString;
|
328 |
|
329 | /**
|
330 | * Reads input string from given files and returns a string containing all lines
|
331 | * of the file that match the given `regex_filter`. Wildcard `*` accepted.
|
332 | *
|
333 | * @param regex_filter The regular expression to use.
|
334 | * @param files The files to process.
|
335 | * @return Returns a string containing all lines of the file that match the given `regex_filter`.
|
336 | */
|
337 | (regex_filter: string | RegExp, files: string[]): ShellString;
|
338 | (regex_filter: string | RegExp, ...files: string[]): ShellString;
|
339 | }
|
340 |
|
341 | /**
|
342 | * Reads input string from given files and returns a string containing all lines
|
343 | * of the file that match the given `regex_filter`. Wildcard `*` accepted.
|
344 | *
|
345 | * @param options Available options:
|
346 | * - `-v`: Inverse the sense of the regex and print
|
347 | * the lines not matching the criteria.
|
348 | * - `-l`: Print only filenames of matching files
|
349 | * @param regex_filter The regular expression to use.
|
350 | * @param files The files to process.
|
351 | * @return Returns a string containing all lines of the file that match the given `regex_filter`.
|
352 | */
|
353 | export const grep: GrepFunction;
|
354 |
|
355 | /**
|
356 | * Searches for command in the system's PATH. On Windows looks for .exe, .cmd, and .bat extensions.
|
357 | *
|
358 | * @param command The command to search for.
|
359 | * @return Returns string containing the absolute path to the command or `null` if it couldn't be found.
|
360 | */
|
361 | export function which(command: string): ShellString | null;
|
362 |
|
363 | export interface EchoFunction {
|
364 | /**
|
365 | * Prints string to stdout, and returns string with additional utility methods like .to().
|
366 | *
|
367 | * @param options Available options:
|
368 | * - `-e`: interpret backslash escapes (default)
|
369 | * - `-n`: remove trailing newline from output
|
370 | * @param text The text to print.
|
371 | * @return Returns the string that was passed as argument.
|
372 | */
|
373 | (options: string, ...text: string[]): ShellString;
|
374 |
|
375 | /**
|
376 | * Prints string to stdout, and returns string with additional utility methods like .to().
|
377 | *
|
378 | * @param text The text to print.
|
379 | * @return Returns the string that was passed as argument.
|
380 | */
|
381 | (...text: string[]): ShellString;
|
382 | }
|
383 |
|
384 | /**
|
385 | * Prints string to stdout, and returns string with additional utility methods like .to().
|
386 | *
|
387 | * @param options Available options:
|
388 | * - `-e`: interpret backslash escapes (default)
|
389 | * - `-n`: remove trailing newline from output
|
390 | * @param text The text to print.
|
391 | * @return Returns the string that was passed as argument.
|
392 | */
|
393 | export const echo: EchoFunction;
|
394 |
|
395 | export interface PushDirFunction {
|
396 | /**
|
397 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
398 | * With no arguments, `pushd` exchanges the top two directories.
|
399 | *
|
400 | * @param options Available options:
|
401 | * - `-n`: Suppresses the normal change of directory when adding directories
|
402 | * to the stack, so that only the stack is manipulated
|
403 | * - `-q`: Suppresses output to the console.
|
404 | * @param dir Brings the Nth directory (counting from the left of the list printed by dirs,
|
405 | * starting with zero) to the top of the list by rotating the stack.
|
406 | * @return Returns an array of paths in the stack.
|
407 | */
|
408 | (options: string, dir: "+N"): ShellArray;
|
409 |
|
410 | /**
|
411 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
412 | * With no arguments, `pushd` exchanges the top two directories.
|
413 | *
|
414 | * @param options Available options:
|
415 | * - `-n`: Suppresses the normal change of directory when adding directories
|
416 | * to the stack, so that only the stack is manipulated
|
417 | * - `-q`: Suppresses output to the console.
|
418 | * @param dir Brings the Nth directory (counting from the right of the list printed by dirs,
|
419 | * starting with zero) to the top of the list by rotating the stack.
|
420 | * @return Returns an array of paths in the stack.
|
421 | */
|
422 | (options: string, dir: "-N"): ShellArray;
|
423 |
|
424 | /**
|
425 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
426 | * With no arguments, `pushd` exchanges the top two directories.
|
427 | *
|
428 | * @param options Available options:
|
429 | * - `-n`: Suppresses the normal change of directory when adding directories
|
430 | * to the stack, so that only the stack is manipulated
|
431 | * - `-q`: Suppresses output to the console.
|
432 | * @param dir Makes the current working directory be the top of the stack,
|
433 | * and then executes the equivalent of `cd dir`.
|
434 | * @return Returns an array of paths in the stack.
|
435 | */
|
436 | (options: string, dir: string): ShellArray;
|
437 |
|
438 | /**
|
439 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
440 | * With no arguments, `pushd` exchanges the top two directories.
|
441 | *
|
442 | * @param dir Brings the Nth directory (counting from the left of the list printed by dirs,
|
443 | * starting with zero) to the top of the list by rotating the stack.
|
444 | * @return Returns an array of paths in the stack.
|
445 | */
|
446 | (dir: "+N"): ShellArray;
|
447 |
|
448 | /**
|
449 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
450 | * With no arguments, `pushd` exchanges the top two directories.
|
451 | *
|
452 | * @param dir Brings the Nth directory (counting from the right of the list printed by dirs,
|
453 | * starting with zero) to the top of the list by rotating the stack.
|
454 | * @return Returns an array of paths in the stack.
|
455 | */
|
456 | (dir: "-N"): ShellArray;
|
457 |
|
458 | /**
|
459 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
460 | * With no arguments, `pushd` exchanges the top two directories.
|
461 | *
|
462 | * @param dir Makes the current working directory be the top of the stack,
|
463 | * and then executes the equivalent of cd dir.
|
464 | * @return Returns an array of paths in the stack.
|
465 | */
|
466 | (dir: string): ShellArray;
|
467 |
|
468 | /**
|
469 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
470 | * With no arguments, `pushd` exchanges the top two directories.
|
471 | *
|
472 | * @return Returns an array of paths in the stack.
|
473 | */
|
474 | (): ShellArray;
|
475 | }
|
476 |
|
477 | /**
|
478 | * Saves the current directory on the top of the directory stack and then cd to dir.
|
479 | * With no arguments, `pushd` exchanges the top two directories.
|
480 | *
|
481 | * @param options Available options:
|
482 | * - `-n`: Suppresses the normal change of directory when adding directories
|
483 | * to the stack, so that only the stack is manipulated
|
484 | * - `-q`: Suppresses output to the console.
|
485 | * @param dir Makes the current working directory be the top of the stack,
|
486 | * and then executes the equivalent of `cd dir`.
|
487 | * @return Returns an array of paths in the stack.
|
488 | */
|
489 | export const pushd: PushDirFunction;
|
490 |
|
491 | export interface PopDirFunction {
|
492 | /**
|
493 | * When no arguments are given, popd removes the top directory from the stack
|
494 | * and performs a `cd` to the new top directory.
|
495 | *
|
496 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
497 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
498 | *
|
499 | * @param options Available options:
|
500 | * - `-n`: Suppresses the normal change of directory when removing directories
|
501 | * from the stack, so that only the stack is manipulated
|
502 | * - `-q`: Suppresses output to the console.
|
503 | * @param dir Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
|
504 | * @return Returns an array of paths in the stack.
|
505 | */
|
506 | (options: string, dir: "+N"): ShellArray;
|
507 |
|
508 | /**
|
509 | * When no arguments are given, popd removes the top directory from the stack
|
510 | * and performs a `cd` to the new top directory.
|
511 | *
|
512 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
513 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
514 | *
|
515 | * @param options Available options:
|
516 | * - `-n`: Suppresses the normal change of directory when removing directories
|
517 | * from the stack, so that only the stack is manipulated
|
518 | * - `-q`: Suppresses output to the console.
|
519 | * @param dir Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
|
520 | * @return Returns an array of paths in the stack.
|
521 | */
|
522 | (options: string, dir: "-N"): ShellArray;
|
523 |
|
524 | /**
|
525 | * When no arguments are given, popd removes the top directory from the stack
|
526 | * and performs a `cd` to the new top directory.
|
527 | *
|
528 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
529 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
530 | *
|
531 | * @param options Available options:
|
532 | * - `-n`: Suppresses the normal change of directory when removing directories
|
533 | * from the stack, so that only the stack is manipulated
|
534 | * - `-q`: Suppresses output to the console.
|
535 | * @param dir You can only use -N and +N.
|
536 | * @return Returns an array of paths in the stack.
|
537 | */
|
538 | (options: string, dir: string): ShellArray;
|
539 |
|
540 | /**
|
541 | * When no arguments are given, popd removes the top directory from the stack
|
542 | * and performs a `cd` to the new top directory.
|
543 | *
|
544 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
545 | * i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
|
546 | *
|
547 | * @param dir Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
|
548 | * @return Returns an array of paths in the stack.
|
549 | */
|
550 | (dir: "+N"): ShellArray;
|
551 |
|
552 | /**
|
553 | * When no arguments are given, popd removes the top directory from the stack
|
554 | * and performs a `cd` to the new top directory.
|
555 | *
|
556 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
557 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
558 | *
|
559 | * @param dir Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
|
560 | * @return Returns an array of paths in the stack.
|
561 | */
|
562 | (dir: "-N"): ShellArray;
|
563 |
|
564 | /**
|
565 | * When no arguments are given, popd removes the top directory from the stack
|
566 | * and performs a `cd` to the new top directory.
|
567 | *
|
568 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
569 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
570 | *
|
571 | * @param dir You can only use -N and +N.
|
572 | * @return Returns an array of paths in the stack.
|
573 | */
|
574 | (dir: string): ShellArray;
|
575 |
|
576 | /**
|
577 | * When no arguments are given, popd removes the top directory from the stack
|
578 | * and performs a `cd` to the new top directory.
|
579 | *
|
580 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
581 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
582 | *
|
583 | * @return Returns an array of paths in the stack.
|
584 | */
|
585 | (): ShellArray;
|
586 | }
|
587 |
|
588 | /**
|
589 | * When no arguments are given, popd removes the top directory from the stack
|
590 | * and performs a `cd` to the new top directory.
|
591 | *
|
592 | * The elements are numbered from 0 starting at the first directory listed with dirs;
|
593 | * i.e., `popd` is equivalent to `popd +0`. Returns an array of paths in the stack.
|
594 | *
|
595 | * @param options Available options:
|
596 | * - `-n`: Suppresses the normal change of directory when removing directories
|
597 | * from the stack, so that only the stack is manipulated
|
598 | * - `-q`: Suppresses output to the console.
|
599 | * @param dir You can only use -N and +N.
|
600 | * @return Returns an array of paths in the stack.
|
601 | */
|
602 | export const popd: PopDirFunction;
|
603 |
|
604 | export interface DirsFunction {
|
605 | /**
|
606 | * Clears the directory stack by deleting all of the elements.
|
607 | *
|
608 | * @param options Clears the directory stack by deleting all of the elements.
|
609 | * @return Returns an array of paths in the stack, or a single path if +N or -N was specified.
|
610 | */
|
611 | (options: "-c"): ShellArray;
|
612 |
|
613 | /**
|
614 | * Displays the list of currently remembered directories.
|
615 | *
|
616 | * @param options Displays the Nth directory (counting from the left of the list
|
617 | * printed by dirs when invoked without options), starting with zero.
|
618 | * @return Returns an array of paths in the stack, or a single path if +N or -N was specified.
|
619 | */
|
620 | (options: "+N"): ShellString;
|
621 |
|
622 | /**
|
623 | * Displays the list of currently remembered directories.
|
624 | *
|
625 | * @param options Displays the Nth directory (counting from the right of the list
|
626 | * printed by dirs when invoked without options), starting with zero.
|
627 | * @return Returns an array of paths in the stack, or a single path if +N or -N was specified.
|
628 | */
|
629 | (options: "-N"): ShellString;
|
630 |
|
631 | /**
|
632 | * Displays the list of currently remembered directories.
|
633 | *
|
634 | * @param options Available options:
|
635 | * - `-c`: Clears the directory stack by deleting all of the elements.
|
636 | * - `-N`: Displays the Nth directory (counting from the right of the list
|
637 | * printed by dirs when invoked without options), starting with zero.
|
638 | * - `+N`: Displays the Nth directory (counting from the left of the list
|
639 | * printed by dirs when invoked without options), starting with zero.
|
640 | * @return Returns an array of paths in the stack, or a single path if +N or -N was specified.
|
641 | */
|
642 | (options: string): ShellArray | ShellString;
|
643 | }
|
644 |
|
645 | /**
|
646 | * Displays the list of currently remembered directories.
|
647 | *
|
648 | * @param options Available options:
|
649 | * - `-c`: Clears the directory stack by deleting all of the elements.
|
650 | * - `-N`: Displays the Nth directory (counting from the right of the list
|
651 | * printed by dirs when invoked without options), starting with zero.
|
652 | * - `+N`: Displays the Nth directory (counting from the left of the list
|
653 | * printed by dirs when invoked without options), starting with zero.
|
654 | * @return Returns an array of paths in the stack, or a single path if +N or -N was specified.
|
655 | */
|
656 | export const dirs: DirsFunction;
|
657 |
|
658 | export interface LinkFunction {
|
659 | /**
|
660 | * Links source to dest. Use `-f` to force the link, should dest already exist.
|
661 | *
|
662 | * @param options Available options:
|
663 | * - `-s`: Create a symbolic link, defaults to a hardlink
|
664 | * - `-f`: Force creation
|
665 | * @param source The source.
|
666 | * @param dest The destination.
|
667 | * @return Object with shell exit code, stderr and stdout.
|
668 | */
|
669 | (options: string, source: string, dest: string): ShellString;
|
670 |
|
671 | /**
|
672 | * Links source to dest. Use `-f` to force the link, should dest already exist.
|
673 | *
|
674 | * @param source The source.
|
675 | * @param dest The destination.
|
676 | * @return Object with shell exit code, stderr and stdout.
|
677 | */
|
678 | (source: string, dest: string): ShellString;
|
679 | }
|
680 |
|
681 | /**
|
682 | * Links source to dest. Use `-f` to force the link, should dest already exist.
|
683 | *
|
684 | * @param options Available options:
|
685 | * - `-s`: Create a symbolic link, defaults to a hardlink
|
686 | * - `-f`: Force creation
|
687 | * @param source The source.
|
688 | * @param dest The destination.
|
689 | * @return Object with shell exit code, stderr and stdout.
|
690 | */
|
691 | export const ln: LinkFunction;
|
692 |
|
693 | /**
|
694 | * Exits the current process with the given exit code.
|
695 | *
|
696 | * Equivalent to calling `process.exit(code)`.
|
697 | *
|
698 | * @param code The exit code.
|
699 | */
|
700 | export function exit(code?: number): never;
|
701 |
|
702 | /**
|
703 | * Object containing environment variables (both getter and setter). Shortcut to `process.env`.
|
704 | */
|
705 | export const env: NodeJS.ProcessEnv;
|
706 |
|
707 | export interface ExecFunction {
|
708 | /**
|
709 | * Executes the given command synchronously.
|
710 | *
|
711 | * @param command The command to execute.
|
712 | * @return Returns an object containing the return code and output as string.
|
713 | */
|
714 | (command: string): ShellString;
|
715 |
|
716 | /**
|
717 | * Executes the given command synchronously.
|
718 | *
|
719 | * @param command The command to execute.
|
720 | * @param options Silence and synchronous options.
|
721 | * @return Returns an object containing the return code and output as string,
|
722 | * or if `{async: true}` was passed, a `ChildProcess`.
|
723 | */
|
724 | (command: string, options: ExecOptions & { async?: false | undefined }): ShellString;
|
725 |
|
726 | /**
|
727 | * Executes the given command asynchronously.
|
728 | *
|
729 | * @param command The command to execute.
|
730 | * @param options Silence and synchronous options.
|
731 | * @return Returns an object containing the return code and output as string,
|
732 | * or if `{async: true}` was passed, a `ChildProcess`.
|
733 | */
|
734 | (command: string, options: ExecOptions & { async: true }): child.ChildProcess;
|
735 |
|
736 | /**
|
737 | * Executes the given command.
|
738 | *
|
739 | * @param command The command to execute.
|
740 | * @param options Silence and synchronous options.
|
741 | * @return Returns an object containing the return code and output as string,
|
742 | * or if `{async: true}` was passed, a `ChildProcess`.
|
743 | */
|
744 | (command: string, options: ExecOptions): ShellString | child.ChildProcess;
|
745 |
|
746 | /**
|
747 | * Executes the given command synchronously.
|
748 | *
|
749 | * @param command The command to execute.
|
750 | * @param options Silence and synchronous options.
|
751 | * @param callback Receives code and output asynchronously.
|
752 | */
|
753 | (command: string, options: ExecOptions, callback: ExecCallback): child.ChildProcess;
|
754 |
|
755 | /**
|
756 | * Executes the given command synchronously.
|
757 | *
|
758 | * @param command The command to execute.
|
759 | * @param callback Receives code and output asynchronously.
|
760 | */
|
761 | (command: string, callback: ExecCallback): child.ChildProcess;
|
762 | }
|
763 |
|
764 | /**
|
765 | * Executes the given command.
|
766 | *
|
767 | * @param command The command to execute.
|
768 | * @param options Silence and synchronous options.
|
769 | * @param [callback] Receives code and output asynchronously.
|
770 | * @return Returns an object containing the return code and output as string,
|
771 | * or if `{async: true}` or a `callback` was passed, a `ChildProcess`.
|
772 | */
|
773 | export const exec: ExecFunction;
|
774 |
|
775 | export type ExecCallback = (
|
776 | /** The process exit code. */
|
777 | code: number,
|
778 | /** The process standard output. */
|
779 | stdout: string,
|
780 | /** The process standard error output. */
|
781 | stderr: string,
|
782 | ) => any;
|
783 |
|
784 | export interface ExecOptions extends child.ExecOptions {
|
785 | /**
|
786 | * Do not echo program output to the console.
|
787 | *
|
788 | * @default false
|
789 | */
|
790 | silent?: boolean | undefined;
|
791 |
|
792 | /**
|
793 | * Exit when command return code is non-zero.
|
794 | *
|
795 | * @default false
|
796 | */
|
797 | fatal?: boolean | undefined;
|
798 |
|
799 | /**
|
800 | * Asynchronous execution.
|
801 | *
|
802 | * If a callback is provided, it will be set to `true`, regardless of the passed value.
|
803 | *
|
804 | * @default false
|
805 | */
|
806 | async?: boolean | undefined;
|
807 |
|
808 | /**
|
809 | * Character encoding to use.
|
810 | *
|
811 | * Affects the values returned by `stdout` and `stderr`,
|
812 | * and what is written to `stdout` and `stderr` when not in silent mode
|
813 | *
|
814 | * @default "utf8"
|
815 | */
|
816 | encoding?: string | undefined;
|
817 | }
|
818 |
|
819 | export interface ExecOutputReturnValue {
|
820 | /** The process exit code. */
|
821 | code: number;
|
822 |
|
823 | /** The process standard output. */
|
824 | stdout: string;
|
825 |
|
826 | /** The process standard error output. */
|
827 | stderr: string;
|
828 | }
|
829 |
|
830 | export interface ShellReturnValue extends ExecOutputReturnValue {
|
831 | /**
|
832 | * Analogous to the redirection operator `>` in Unix, but works with JavaScript strings
|
833 | * (such as those returned by `cat`, `grep`, etc).
|
834 | *
|
835 | * Like Unix redirections, `to()` will overwrite any existing file!
|
836 | *
|
837 | * @param file The file to use.
|
838 | */
|
839 | to(file: string): void;
|
840 |
|
841 | /**
|
842 | * Analogous to the redirect-and-append operator `>>` in Unix, but works with JavaScript strings
|
843 | * (such as those returned by `cat`, `grep`, etc).
|
844 | *
|
845 | * @param file The file to append to.
|
846 | */
|
847 | toEnd(file: string): void;
|
848 |
|
849 | /**
|
850 | * Returns a string containing the given pipeline, or a concatenated string
|
851 | * containing the pipelines if more than one input stream is given
|
852 | * (a new line character is introduced between each input).
|
853 | *
|
854 | * @return A string containing the given pipeline, or a concatenated string
|
855 | * containing the pipelines if more than one input stream is given
|
856 | * (a new line character is introduced between each input).
|
857 | */
|
858 | cat: CatFunction;
|
859 |
|
860 | /**
|
861 | * Executes the given command.
|
862 | *
|
863 | * @param command The command to execute.
|
864 | * @param options Silence and synchronous options.
|
865 | * @param [callback] Receives code and output asynchronously.
|
866 | * @return Returns an object containing the return code and output as string,
|
867 | * or if `{async: true}` or a `callback` was passed, a `ChildProcess`.
|
868 | */
|
869 | exec: ExecFunction;
|
870 |
|
871 | /**
|
872 | * Read the start of a pipeline input.
|
873 | */
|
874 | head: HeadFunction;
|
875 |
|
876 | /**
|
877 | * Reads input string from given files and returns a string containing all lines
|
878 | * of the file that match the given `regex_filter`. Wildcard `*` accepted.
|
879 | *
|
880 | * @param options Available options:
|
881 | * - `-v`: Inverse the sense of the regex and print
|
882 | * the lines not matching the criteria.
|
883 | * - `-l`: Print only filenames of matching files
|
884 | * @param regex_filter The regular expression to use.
|
885 | * @return Returns a string containing all lines of the file that match the given `regex_filter`.
|
886 | */
|
887 | grep: GrepFunction;
|
888 |
|
889 | /**
|
890 | * Reads an input string from pipeline and performs a JavaScript `replace()`
|
891 | * on the input using the given search regex and replacement string or function.
|
892 | *
|
893 | * @param options Available options:
|
894 | * - `-i`: Replace contents of 'file' in-place. Note that no backups will be created!
|
895 | * @param searchRegex The regular expression to use for search.
|
896 | * @param replacement The replacement.
|
897 | * @return The new string after replacement.
|
898 | */
|
899 | sed: SedFunction;
|
900 |
|
901 | /**
|
902 | * Return the contents of the pipeline, sorted line-by-line.
|
903 | *
|
904 | * @param options Available options:
|
905 | * - `-r`: Reverse the results
|
906 | * - `-n`: Compare according to numerical value
|
907 | */
|
908 | sort: SortFunction;
|
909 |
|
910 | /**
|
911 | * Read the end of a pipeline input.
|
912 | */
|
913 | tail: TailFunction;
|
914 |
|
915 | /**
|
916 | * Filter adjacent matching lines from input.
|
917 | *
|
918 | * @param options Available options:
|
919 | * - `-i`: Ignore case while comparing
|
920 | * - `-c`: Prefix lines by the number of occurrences
|
921 | * - `-d`: Only print duplicate lines, one for each group of identical lines
|
922 | */
|
923 | uniq: UniqFunction;
|
924 | }
|
925 |
|
926 | export type ShellString = string & ShellReturnValue;
|
927 |
|
928 | export type ShellArray = string[] & ShellReturnValue;
|
929 |
|
930 | export interface ShellStringConstructor {
|
931 | /**
|
932 | * Wraps a string (or array) value. This has all the string (or array) methods,
|
933 | * but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able
|
934 | * methods (ex. `.cat()`, `.grep()`, etc.).
|
935 | *
|
936 | * This can be easily converted into a string by calling `.toString()`.
|
937 | *
|
938 | * This type also exposes the corresponding command's stdout, stderr, and return status
|
939 | * code via the `.stdout` (string), `.stderr` (string), and `.code` (number) properties
|
940 | * respectively.
|
941 | *
|
942 | * Construct signature allows for:
|
943 | *
|
944 | * var foo = new ShellString('hello world');
|
945 | *
|
946 | * as per example in shelljs docs:
|
947 | * https://github.com/shelljs/shelljs#shellstringstr
|
948 | *
|
949 | * @param value The string value to wrap.
|
950 | * @return A string-like object with special methods.
|
951 | */
|
952 | new(value: string): ShellString;
|
953 | new(value: string[]): ShellArray;
|
954 |
|
955 | /**
|
956 | * Wraps a string (or array) value. This has all the string (or array) methods,
|
957 | * but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able
|
958 | * methods (ex. `.cat()`, `.grep()`, etc.).
|
959 | *
|
960 | * This can be easily converted into a string by calling `.toString()`.
|
961 | *
|
962 | * This type also exposes the corresponding command's stdout, stderr, and return status
|
963 | * code via the `.stdout` (string), `.stderr` (string), and `.code` (number) properties
|
964 | * respectively.
|
965 | *
|
966 | * @param value The string value to wrap.
|
967 | * @return A string-like object with special methods.
|
968 | */
|
969 | (value: string): ShellString;
|
970 | (value: string[]): ShellArray;
|
971 | }
|
972 |
|
973 | export const ShellString: ShellStringConstructor;
|
974 |
|
975 | export interface ChmodFunction {
|
976 | /**
|
977 | * Alters the permissions of a file or directory by either specifying the absolute
|
978 | * permissions in octal form or expressing the changes in symbols.
|
979 | *
|
980 | * This command tries to mimic the POSIX behavior as much as possible.
|
981 | *
|
982 | * Notable exceptions:
|
983 | * - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
|
984 | * - There is no "quiet" option since default behavior is to run silent.
|
985 | *
|
986 | * @param options Available options:
|
987 | * - `-v`: output a diagnostic for every file processed
|
988 | * - `-c`: like -v but report only when a change is made
|
989 | * - `-R`: change files and directories recursively
|
990 | * @param mode The access mode. Can be an octal string or a symbolic mode string.
|
991 | * @param file The file to use.
|
992 | * @return Object with shell exit code, stderr and stdout.
|
993 | */
|
994 | (options: string, mode: string | number, file: string): ShellString;
|
995 |
|
996 | /**
|
997 | * Alters the permissions of a file or directory by either specifying the absolute
|
998 | * permissions in octal form or expressing the changes in symbols.
|
999 | *
|
1000 | * This command tries to mimic the POSIX behavior as much as possible.
|
1001 | *
|
1002 | * Notable exceptions:
|
1003 | * - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
|
1004 | * - There is no "quiet" option since default behavior is to run silent.
|
1005 | *
|
1006 | * @param mode The access mode. Can be an octal string or a symbolic mode string.
|
1007 | * @param file The file to use.
|
1008 | * @return Object with shell exit code, stderr and stdout.
|
1009 | */
|
1010 | (mode: string | number, file: string): ShellString;
|
1011 | }
|
1012 |
|
1013 | /**
|
1014 | * Alters the permissions of a file or directory by either specifying the absolute
|
1015 | * permissions in octal form or expressing the changes in symbols.
|
1016 | *
|
1017 | * This command tries to mimic the POSIX behavior as much as possible.
|
1018 | *
|
1019 | * Notable exceptions:
|
1020 | * - In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
|
1021 | * - There is no "quiet" option since default behavior is to run silent.
|
1022 | *
|
1023 | * @param options Available options:
|
1024 | * - `-v`: output a diagnostic for every file processed
|
1025 | * - `-c`: like -v but report only when a change is made
|
1026 | * - `-R`: change files and directories recursively
|
1027 | * @param mode The access mode. Can be an octal string or a symbolic mode string.
|
1028 | * @param file The file to use.
|
1029 | * @return Object with shell exit code, stderr and stdout.
|
1030 | */
|
1031 | export const chmod: ChmodFunction;
|
1032 |
|
1033 | // Non-Unix commands
|
1034 |
|
1035 | /**
|
1036 | * Searches and returns string containing a writeable, platform-dependent temporary directory.
|
1037 | * Follows Python's tempfile algorithm.
|
1038 | *
|
1039 | * @return The temp file path.
|
1040 | */
|
1041 | export function tempdir(): ShellString;
|
1042 |
|
1043 | /**
|
1044 | * Tests if error occurred in the last command.
|
1045 | *
|
1046 | * @return Returns null if no error occurred, otherwise returns string explaining the error
|
1047 | */
|
1048 | export function error(): ShellString;
|
1049 |
|
1050 | export type TouchOptionsLiteral = "-a" | "-c" | "-m" | "-d" | "-r";
|
1051 |
|
1052 | export interface TouchOptionsArray {
|
1053 | "-d"?: string | undefined;
|
1054 | "-r"?: string | undefined;
|
1055 | }
|
1056 |
|
1057 | export interface TouchFunction {
|
1058 | (options: TouchOptionsLiteral | TouchOptionsArray, files: string[]): ShellString;
|
1059 | (options: TouchOptionsLiteral | TouchOptionsArray, ...files: string[]): ShellString;
|
1060 |
|
1061 | (files: string[]): ShellString;
|
1062 | (...files: string[]): ShellString;
|
1063 | }
|
1064 |
|
1065 | /**
|
1066 | * Update the access and modification times of each FILE to the current time.
|
1067 | * A FILE argument that does not exist is created empty, unless `-c` is supplied
|
1068 | */
|
1069 | export const touch: TouchFunction;
|
1070 |
|
1071 | export interface HeadOptions {
|
1072 | /** Show the first <num> lines of the files. */
|
1073 | "-n": number;
|
1074 | }
|
1075 |
|
1076 | export interface HeadFunction {
|
1077 | (options: HeadOptions, files: string[]): ShellString;
|
1078 | (options: HeadOptions, ...files: string[]): ShellString;
|
1079 |
|
1080 | (files: string[]): ShellString;
|
1081 | (...files: string[]): ShellString;
|
1082 | }
|
1083 |
|
1084 | /**
|
1085 | * Read the start of a file.
|
1086 | */
|
1087 | export const head: HeadFunction;
|
1088 |
|
1089 | export interface SortFunction {
|
1090 | /**
|
1091 | * Return the contents of the files, sorted line-by-line.
|
1092 | * Sorting multiple files mixes their content (just as unix sort does).
|
1093 | *
|
1094 | * @param options Available options:
|
1095 | * - `-r`: Reverse the results
|
1096 | * - `-n`: Compare according to numerical value
|
1097 | */
|
1098 | (options: string, files: string[]): ShellString;
|
1099 | (options: string, ...files: string[]): ShellString;
|
1100 |
|
1101 | /**
|
1102 | * Return the contents of the files, sorted line-by-line.
|
1103 | * Sorting multiple files mixes their content (just as unix sort does).
|
1104 | */
|
1105 | (files: string[]): ShellString;
|
1106 | (...files: string[]): ShellString;
|
1107 | }
|
1108 |
|
1109 | /**
|
1110 | * Return the contents of the files, sorted line-by-line.
|
1111 | * Sorting multiple files mixes their content (just as unix sort does).
|
1112 | *
|
1113 | * @param options Available options:
|
1114 | * - `-r`: Reverse the results
|
1115 | * - `-n`: Compare according to numerical value
|
1116 | */
|
1117 | export const sort: SortFunction;
|
1118 |
|
1119 | export interface TailOptions {
|
1120 | /** Show the last <num> lines of files. */
|
1121 | "-n": number;
|
1122 | }
|
1123 |
|
1124 | export interface TailFunction {
|
1125 | (options: TailOptions, files: string[]): ShellString;
|
1126 | (options: TailOptions, ...files: string[]): ShellString;
|
1127 |
|
1128 | (files: string[]): ShellString;
|
1129 | (...files: string[]): ShellString;
|
1130 | }
|
1131 |
|
1132 | /**
|
1133 | * Read the end of a file.
|
1134 | */
|
1135 | export const tail: TailFunction;
|
1136 |
|
1137 | export interface UniqFunction {
|
1138 | /**
|
1139 | * Filter adjacent matching lines from input.
|
1140 | *
|
1141 | * @param options Available options:
|
1142 | * - `-i`: Ignore case while comparing
|
1143 | * - `-c`: Prefix lines by the number of occurrences
|
1144 | * - `-d`: Only print duplicate lines, one for each group of identical lines
|
1145 | */
|
1146 | (options: string, input: string, output?: string): ShellString;
|
1147 |
|
1148 | /**
|
1149 | * Filter adjacent matching lines from input.
|
1150 | */
|
1151 | (input: string, output?: string): ShellString;
|
1152 | }
|
1153 |
|
1154 | /**
|
1155 | * Filter adjacent matching lines from input.
|
1156 | *
|
1157 | * @param options Available options:
|
1158 | * - `-i`: Ignore case while comparing
|
1159 | * - `-c`: Prefix lines by the number of occurrences
|
1160 | * - `-d`: Only print duplicate lines, one for each group of identical lines
|
1161 | */
|
1162 | export const uniq: UniqFunction;
|
1163 |
|
1164 | /**
|
1165 | * Sets global configuration variables
|
1166 | * @param options Available options:
|
1167 | * - `+/-e`: exit upon error (`config.fatal`),
|
1168 | * - `+/-v`: verbose: show all commands (`config.verbose`),
|
1169 | * - `+/-f`: disable filename expansion (globbing)
|
1170 | */
|
1171 | export function set(options: string): void;
|
1172 |
|
1173 | // Configuration
|
1174 |
|
1175 | export interface ShellConfig {
|
1176 | /**
|
1177 | * Suppresses all command output if true, except for echo() calls. Default is false.
|
1178 | */
|
1179 | silent: boolean;
|
1180 |
|
1181 | /**
|
1182 | * If true the script will die on errors. Default is false.
|
1183 | */
|
1184 | fatal: boolean;
|
1185 |
|
1186 | /**
|
1187 | * Will print each executed command to the screen.
|
1188 | *
|
1189 | * @default false
|
1190 | */
|
1191 | verbose: boolean;
|
1192 |
|
1193 | /**
|
1194 | * Passed to glob.sync() instead of the default options ({}).
|
1195 | */
|
1196 | globOptions: glob.IOptions;
|
1197 |
|
1198 | /**
|
1199 | * Absolute path of the Node binary. Default is null (inferred).
|
1200 | */
|
1201 | execPath: string | null;
|
1202 |
|
1203 | /**
|
1204 | * Reset shell.config to the defaults.
|
1205 | */
|
1206 | reset(): void;
|
1207 | }
|
1208 |
|
1209 | /**
|
1210 | * The shelljs configuration.
|
1211 | */
|
1212 | export const config: ShellConfig;
|