-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
index.d.ts
182 lines (139 loc) · 3.44 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import {type Options as GlobOptions} from 'globby';
import {type Options as CopyFileOptions} from 'copy-file';
export type Entry = {
/**
Resolved path to the file.
@example '/tmp/dir/foo.js'
*/
readonly path: string;
/**
Relative path to the file from cwd.
@example 'dir/foo.js'
*/
readonly relativePath: string;
/**
Filename with extension.
@example 'foo.js'
*/
readonly name: string;
/**
Filename without extension.
@example 'foo'
*/
readonly nameWithoutExtension: string;
/**
File extension.
@example 'js'
*/
readonly extension: string;
};
export type Options = {
/**
Working directory to find source files.
@default process.cwd()
*/
readonly cwd?: string;
/**
Flatten directory tree.
@default false
*/
readonly flat?: boolean;
/**
Filename or function returning a filename used to rename every file in `source`.
@example
```
import cpy from 'cpy';
await cpy('foo.js', 'destination', {
// The `basename` is the filename with extension.
rename: basename => `prefix-${basename}`
});
await cpy('foo.js', 'destination', {
rename: 'new-name'
});
```
*/
readonly rename?: string | ((basename: string) => string);
/**
Number of files being copied concurrently.
@default (os.cpus().length || 1) * 2
*/
readonly concurrency?: number;
/**
Ignore junk files.
@default true
*/
readonly ignoreJunk?: boolean;
/**
Function to filter files to copy.
Receives a source file object as the first argument.
Return true to include, false to exclude. You can also return a Promise that resolves to true or false.
@example
```
import cpy from 'cpy';
await cpy('foo', 'destination', {
filter: file => file.extension !== 'nocopy'
});
```
*/
readonly filter?: (file: Entry) => boolean | Promise<boolean>;
} & Readonly<GlobOptions> & CopyFileOptions;
export type 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;
/**
The absolute source path of the current file being copied.
*/
sourcePath: string;
/**
The absolute destination path of the current file being copied.
*/
destinationPath: string;
};
export type ProgressEmitter = {
on(
event: 'progress',
handler: (progress: ProgressData) => void
): Promise<string[]>;
};
/**
Copy files.
@param source - Files to copy. If any of the files do not exist, an error will be thrown (does not apply to globs).
@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 from 'cpy';
await cpy([
'source/*.png', // Copy all .png files
'!source/goat.png', // Ignore goat.png
], 'destination');
// Copy node_modules to destination/node_modules
await cpy('node_modules', 'destination');
// Copy node_modules content to destination
await cpy('node_modules/**', 'destination');
// Copy node_modules structure but skip all files except any .json files
await cpy('node_modules/**\/*.json', 'destination');
// Copy all png files into destination without keeping directory structure
await cpy('**\/*.png', 'destination', {flat: true});
console.log('Files copied!');
```
*/
export default function cpy(
source: string | readonly string[],
destination: string,
options?: Options
): Promise<string[]> & ProgressEmitter;