From 0c236faad38151973ac0829a142e3dc4d3abb83f Mon Sep 17 00:00:00 2001 From: Paul Huynh Date: Tue, 15 May 2018 00:43:50 +1000 Subject: [PATCH] Update shelljs typings for v0.8 --- types/shelljs/index.d.ts | 82 +++++++++++++++++++++++++++++----- types/shelljs/shelljs-tests.ts | 15 +++++++ 2 files changed, 87 insertions(+), 10 deletions(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 601668f65f..1f1eb5c375 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -1,8 +1,9 @@ -// Type definitions for ShellJS 0.7 +// Type definitions for ShellJS 0.8 // Project: http://shelljs.org // Definitions by: Niklas Mollenhauer // Vojtech Jasny // George Kalpakas +// Paul Huynh // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -11,10 +12,10 @@ import child = require("child_process"); import glob = require("glob"); /** - * Changes to directory dir for the duration of the script + * Changes to directory dir for the duration of the script. Changes to home directory if no argument is supplied. * @param dir Directory to change in. */ -export function cd(dir: string): void; +export function cd(dir?: string): void; /** * Returns the current directory. @@ -31,7 +32,7 @@ export function ls(...paths: Array): ShellArray; /** * Returns array of files in the given path, or in current directory if no path provided. - * @param options Available options: -R (recursive), -A (all files, include files beginning with ., except for . and ..) + * @param options Available options: -R: recursive -A: all files (include files beginning with ., except for . and ..) -L: follow symlinks -d: list directories themselves, not their contents -l: list objects representing each file, each with fields containing ls -l output fields. See fs.Stats for more info * @param ...paths Paths to search. * @return An array of files in the given path(s). */ @@ -53,7 +54,7 @@ export function cp(source: string | string[], dest: string): void; /** * Copies files. The wildcard * is accepted. - * @param options Available options: -f (force), -r, -R (recursive) + * @param options Available options: -f: force (default behavior) -n: no-clobber -u: only copy if source is newer than dest -r, -R: recursive -L: follow symlinks -P: don't follow symlinks * @param source The source. * @param dest The destination. */ @@ -79,6 +80,14 @@ export function rm(options: string, ...files: Array): void; */ export function mv(source: string | string[], dest: string): void; +/** + * Moves files. The wildcard * is accepted. + * @param options Available options: -f: force (default behavior) -n: no-clobber + * @param source The source. + * @param dest The destination. + */ +export function mv(options: string, source: string | string[], dest: string): void; + /** * Creates directories. * @param ...dir Directories to create. @@ -138,7 +147,7 @@ export function grep(regex_filter: string | RegExp, ...files: Array any; export interface ExecOptions extends child.ExecOptions { + /** Do not echo program output to console (default: false). */ silent?: boolean; + /** Asynchronous execution. If a callback is provided, it will be set to true, regardless of the passed value (default: false). */ async?: boolean; + /** Character encoding to use. Affects the values returned to stdout and stderr, and what is written to stdout and stderr when not in silent mode (default: 'utf8'). */ + encoding?: string; } export interface ExecOutputReturnValue { @@ -440,6 +461,47 @@ export function touch(files: string[]): void; export function touch(options: TouchOptionsLiteral, ...files: Array): void; export function touch(options: TouchOptionsArray, ...files: Array): void; +export interface HeadOptions { + /** Show the first lines of the files. */ + '-n': number; +} + +/** Read the start of a file. */ +export function head(...files: Array): ShellString; +/** Read the start of a file. */ +export function head(options: HeadOptions, ...files: Array): ShellString; + +/** + * Return the contents of the files, sorted line-by-line. Sorting multiple files mixes their content (just as unix sort does). + */ +export function sort(...files: Array): ShellString; + +/** + * Return the contents of the files, sorted line-by-line. Sorting multiple files mixes their content (just as unix sort does). + * @param options Available options: -r: Reverse the results -n: Compare according to numerical value + */ +export function sort(options: string, ...files: Array): ShellString; + +export interface TailOptions { + /** Show the last lines of files. */ + '-n': number; +} + +/** Read the end of a file. */ +export function tail(...files: Array): ShellString; +/** Read the end of a file. */ +export function tail(options: TailOptions, ...files: Array): ShellString; + +/** + * Filter adjacent matching lines from input. + */ +export function uniq(input: string, output?: string): ShellString; +/** + * Filter adjacent matching lines from input. + * @param options Available options: -i: Ignore case while comparing -c: Prefix lines by the number of occurrences -d: Only print duplicate lines, one for each group of identical lines + */ +export function uniq(options: string, input: string, output?: string): ShellString; + /** * Sets global configuration variables * @param options Available options: `+/-e`: exit upon error (`config.fatal`), `+/-v`: verbose: show all commands (`config.verbose`), `+/-f`: disable filename expansion (globbing) diff --git a/types/shelljs/shelljs-tests.ts b/types/shelljs/shelljs-tests.ts index da3175f5c6..37dccddff6 100644 --- a/types/shelljs/shelljs-tests.ts +++ b/types/shelljs/shelljs-tests.ts @@ -135,6 +135,21 @@ shell.touch({ '-r': '/some/file.txt' }, '/Users/brandom/test1'); shell.touch({ '-r': '/some/file.txt' }, '/Users/brandom/test1', '/Users/brandom/test2'); shell.touch({ '-r': '/oome/file.txt' }, ['/Users/brandom/test1', '/Users/brandom/test2']); +shell.head({'-n': 1}, 'file*.txt'); +shell.head('file1', 'file2'); +shell.head(['file1', 'file2']); // same as above + +shell.sort('foo.txt', 'bar.txt'); +shell.sort('-r', 'foo.txt'); + +shell.tail({'-n': 1}, 'file*.txt'); +shell.tail('file1', 'file2'); +shell.tail(['file1', 'file2']); // same as above + +shell.uniq('foo.txt'); +shell.uniq('-i', 'foo.txt'); +shell.uniq('-cd', 'foo.txt', 'bar.txt'); + const tmp = shell.tempdir(); // "/tmp" for most *nix platforms const errorlol = shell.error();