diff --git a/types/cp-file/cp-file-tests.ts b/types/cp-file/cp-file-tests.ts new file mode 100644 index 0000000000..173a650e8f --- /dev/null +++ b/types/cp-file/cp-file-tests.ts @@ -0,0 +1,19 @@ +import cpFile = require('cp-file'); + +cpFile('src/unicorn.png', 'dist/unicorn.png').then(() => {}); +cpFile('src/unicorn.png', 'dist/unicorn.png', {overwrite: false}).then(() => {}); +cpFile('src/unicorn.png', 'dist/unicorn.png') + .on('progress', data => { + let str: string; + let num: number; + + str = data.src; + str = data.dest; + num = data.size; + num = data.written; + num = data.percent; + }) + .then(() => {}); + +cpFile.sync('src/unicorn.png', 'dist/unicorn.png'); +cpFile.sync('src/unicorn.png', 'dist/unicorn.png', {overwrite: false}); diff --git a/types/cp-file/index.d.ts b/types/cp-file/index.d.ts new file mode 100644 index 0000000000..d0966f4c85 --- /dev/null +++ b/types/cp-file/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for cp-file 4.2 +// Project: https://github.com/sindresorhus/cp-file#readme +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = cpFile; + +declare function cpFile(source: string, destination: string, options?: cpFile.Options): Promise & cpFile.ProgressEmitter; + +declare namespace cpFile { + function sync(source: string, destination: string, options?: Options): void; + + interface ProgressEmitter { + on(event: 'progress', handler: (data: ProgressData) => void): Promise; + } + + interface Options { + overwrite?: boolean; + } + + interface ProgressData { + src: string; + dest: string; + size: number; + written: number; + percent: number; + } +} diff --git a/types/cp-file/tsconfig.json b/types/cp-file/tsconfig.json new file mode 100644 index 0000000000..ab4eca94d8 --- /dev/null +++ b/types/cp-file/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cp-file-tests.ts" + ] +} diff --git a/types/cp-file/tslint.json b/types/cp-file/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cp-file/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/cpy/cpy-tests.ts b/types/cpy/cpy-tests.ts index 3bc0cbb32a..1800ab35bf 100644 --- a/types/cpy/cpy-tests.ts +++ b/types/cpy/cpy-tests.ts @@ -1,9 +1,18 @@ import cpy = require('cpy'); -cpy(['src/*.png', '!src/goat.png'], 'dist').then(() => { - console.log('files copied'); -}); - +cpy(['src/*.png', '!src/goat.png'], 'dist').then(() => {}); cpy('foo.js', 'destination', { - rename: basename => `prefix-${basename}` + rename: basename => `prefix-${basename}`, + cwd: '/', + parents: true, + stat: true, + overwrite: false, }); +cpy('foo.js', 'destination') + .on('progress', progress => { + let num: number; + num = progress.completedFiles; + num = progress.totalFiles; + num = progress.completedSize; + }) + .then(() => {}); diff --git a/types/cpy/index.d.ts b/types/cpy/index.d.ts index 8ef585250b..b6ca781137 100644 --- a/types/cpy/index.d.ts +++ b/types/cpy/index.d.ts @@ -1,10 +1,31 @@ -// Type definitions for cpy 5.0 +// Type definitions for cpy 5.1 // Project: https://github.com/sindresorhus/cpy#readme // Definitions by: Mohamed Hegazy +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import glob = require('glob'); +import cpFile = require('cp-file'); + export = cpy; -declare function cpy( - src: string | string[], - dest: string, - opts?: { cwd?: string, parents?: boolean, rename?(s: string): string }): Promise; +declare function cpy(files: string | string[], destination: string, opts?: cpy.Options): Promise & cpy.ProgressEmitter; + +declare namespace cpy { + interface ProgressEmitter { + on(event: 'progress', handler: (progress: ProgressData) => void): Promise; + } + + type Options = CpyOptions & glob.IOptions & cpFile.Options; + + interface CpyOptions { + cwd?: string; + parents?: boolean; + rename?: string | ((basename: string) => string); + } + + interface ProgressData { + completedFiles: number; + totalFiles: number; + completedSize: number; + } +} diff --git a/types/cpy/tsconfig.json b/types/cpy/tsconfig.json index 6cb55952aa..75f61a1e5d 100644 --- a/types/cpy/tsconfig.json +++ b/types/cpy/tsconfig.json @@ -2,8 +2,7 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6", - "dom" + "es6" ], "noImplicitAny": true, "noImplicitThis": true, @@ -20,4 +19,4 @@ "index.d.ts", "cpy-tests.ts" ] -} \ No newline at end of file +}