[cpy] update typings to 5.1; [cp-file] add typings (#18737)

This commit is contained in:
Dimitri Benin
2017-08-08 22:47:38 +02:00
committed by Mohamed Hegazy
parent b3a05b5314
commit ded90b265d
7 changed files with 112 additions and 13 deletions

View File

@@ -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});

28
types/cp-file/index.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
// Type definitions for cp-file 4.2
// Project: https://github.com/sindresorhus/cp-file#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = cpFile;
declare function cpFile(source: string, destination: string, options?: cpFile.Options): Promise<void> & cpFile.ProgressEmitter;
declare namespace cpFile {
function sync(source: string, destination: string, options?: Options): void;
interface ProgressEmitter {
on(event: 'progress', handler: (data: ProgressData) => void): Promise<void>;
}
interface Options {
overwrite?: boolean;
}
interface ProgressData {
src: string;
dest: string;
size: number;
written: number;
percent: number;
}
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@@ -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(() => {});

31
types/cpy/index.d.ts vendored
View File

@@ -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 <https://github.com/mhegazy>
// BendingBender <https://github.com/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<void>;
declare function cpy(files: string | string[], destination: string, opts?: cpy.Options): Promise<void> & cpy.ProgressEmitter;
declare namespace cpy {
interface ProgressEmitter {
on(event: 'progress', handler: (progress: ProgressData) => void): Promise<void>;
}
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;
}
}

View File

@@ -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"
]
}
}