From 112e4216d7a68b9140c21252cff585d10e1d4635 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Fri, 25 Jan 2019 10:20:44 +0100 Subject: [PATCH] fix(copy): Add JSDoc, use File --- types/copy/index.d.ts | 59 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/types/copy/index.d.ts b/types/copy/index.d.ts index 175a07e216..567d6594d3 100644 --- a/types/copy/index.d.ts +++ b/types/copy/index.d.ts @@ -7,10 +7,41 @@ import File = require('vinyl'); declare namespace copy { - function each(files: string[], dir: string, options: Options, callback: Callback): void; - function each(files: string[], dir: string, callback: Callback): void; - function one(pattern: string | object, dir: string, options: Options, callback: Callback): void; - function one(pattern: string | object, dir: string, callback: Callback): void; + /** + * Copy an array of files to the given destination `directory`, with + * `options` and callback function that exposes `err` and the array of + * vinyl files that are created by the copy operation. + * + * ```js + * copy.each(['foo.txt', 'bar.txt', 'baz.txt'], 'dist', function(err, files) { + * // exposes the vinyl `files` created when the files are copied + * }); + * ``` + * @param `files` Filepaths or vinyl files. + * @param `dir` Destination directory + * @param `options` or callback function + * @param `cb` Callback function if no options are specified + */ + function each(files: string[] | File[], dir: string, options: Options, cb: Callback): void; + function each(files: string[] | File[], dir: string, cb: Callback): void; + + /** + * Copy a single `file` to the given `dest` directory, using + * the specified options and callback function. + * + * ```js + * copy.one('foo.txt', 'dist', function(err, file) { + * if (err) throw err; + * // exposes the vinyl `file` that is created when the file is copied + * }); + * ``` + * @param `file` Filepath or vinyl file + * @param `dir` Destination directory + * @param `options` or callback function + * @param `cb` Callback function if no options are specified + */ + function one(pattern: string | File, dir: string, options: Options, cb: Callback): void; + function one(pattern: string | File, dir: string, cb: Callback): void; type Callback = (error: Error | null, files?: File[]) => void; @@ -20,12 +51,28 @@ declare namespace copy { } } +/** + * Copy a filepath, vinyl file, array of files, or glob of files to the + * given destination `directory`, with `options` and callback function that + * exposes `err` and the array of vinyl files that are created by the copy + * operation. + * + * ```js + * copy('*.js', 'dist', function(err, file) { + * // exposes the vinyl `file` created when the file is copied + * }); + * ``` + * @param `patterns` Filepath(s), vinyl file(s) or glob of files. + * @param `dir` Destination directory + * @param `options` or callback function + * @param `cb` Callback function if no options are specified + */ declare function copy( - patterns: string | object | string[], + patterns: string | File | string[] | File[], dir: string, options: copy.Options, callback: copy.Callback, ): void; -declare function copy(patterns: string | object | string[], dir: string, callback: copy.Callback): void; +declare function copy(patterns: string | File | string[] | File[], dir: string, callback: copy.Callback): void; export = copy;