/
index.d.ts
129 lines (105 loc) · 2.36 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import {GlobbyOptions} from 'globby';
import {Options as CpFileOptions} from 'cp-file';
declare namespace cpy {
interface SourceFile {
/**
Resolved path to file.
*/
readonly path: string,
/**
Filename.
*/
readonly name: string,
/**
Filename without extension.
*/
readonly nameWithoutExtension: string,
/**
File extension.
*/
readonly extension: string,
}
interface Options extends Readonly<GlobbyOptions>, CpFileOptions {
/**
Working directory to find source files.
@default process.cwd()
*/
readonly cwd?: string;
/**
Preserve path structure.
@default false
*/
readonly parents?: boolean;
/**
Filename or function returning a filename used to rename every file in `source`.
@example
```
import cpy = require('cpy');
(async () => {
await cpy('foo.js', 'destination', {
rename: basename => `prefix-${basename}`
});
})();
```
*/
readonly rename?: string | ((basename: string) => string);
/**
Function to filter files to copy. Should accept source file object as argument.
Return true to include, false to exclude. Can also return a Promise that resolves to true or false.
@example
```
import cpy = require('cpy');
(async () => {
await cpy('foo', 'destination', {
filter: file => file.extension !== '.nocopy'
});
})();
```
*/
readonly filter?: (file: SourceFile) => (boolean | Promise<boolean>);
}
interface ProgressData {
/**
Copied file count.
*/
completedFiles: number;
/**
Overall file count.
*/
totalFiles: number;
/**
Completed size in bytes.
*/
completedSize: number;
/**
Completed percentage. A value between `0` and `1`.
*/
percent: number;
}
interface ProgressEmitter {
on(
event: 'progress',
handler: (progress: ProgressData) => void
): Promise<string[]>;
}
}
/**
Copy files.
@param source - Files to copy.
@param destination - Destination directory.
@param options - In addition to the options defined here, options are passed to [globby](https://github.com/sindresorhus/globby#options).
@example
```
import cpy = require('cpy');
(async () => {
await cpy(['source/*.png', '!source/goat.png'], 'destination');
console.log('Files copied!');
})();
```
*/
declare function cpy(
source: string | ReadonlyArray<string>,
destination: string,
options?: cpy.Options
): Promise<string[]> & cpy.ProgressEmitter;
export = cpy;