-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
index.ts
73 lines (66 loc) · 2.09 KB
/
index.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
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { copyDirectory } from './copy';
import { fingerprint } from './fingerprint';
import { CopyOptions, FingerprintOptions } from './options';
export * from './ignore';
export * from './options';
/**
* File system utilities.
*/
export class FileSystem {
/**
* Copies an entire directory structure.
* @param srcDir Source directory
* @param destDir Destination directory
* @param options options
* @param rootDir Root directory to calculate exclusions from
*/
public static copyDirectory(srcDir: string, destDir: string, options: CopyOptions = { }, rootDir?: string) {
return copyDirectory(srcDir, destDir, options, rootDir);
}
/**
* Produces fingerprint based on the contents of a single file or an entire directory tree.
*
* Line endings are converted from CRLF to LF.
*
* The fingerprint will also include:
* 1. An extra string if defined in `options.extra`.
* 2. The symlink follow mode value.
*
* @param fileOrDirectory The directory or file to fingerprint
* @param options Fingerprinting options
*/
public static fingerprint(fileOrDirectory: string, options: FingerprintOptions = { }) {
return fingerprint(fileOrDirectory, options);
}
/**
* Checks whether a directory is empty
*
* @param dir The directory to check
*/
public static isEmpty(dir: string): boolean {
return fs.readdirSync(dir).length === 0;
}
/**
* The real path of the system temp directory
*/
public static get tmpdir(): string {
if (FileSystem._tmpdir) {
return FileSystem._tmpdir;
}
FileSystem._tmpdir = fs.realpathSync(os.tmpdir());
return FileSystem._tmpdir;
}
/**
* Creates a unique temporary directory in the **system temp directory**.
*
* @param prefix A prefix for the directory name. Six random characters
* will be generated and appended behind this prefix.
*/
public static mkdtemp(prefix: string): string {
return fs.mkdtempSync(path.join(FileSystem.tmpdir, prefix));
}
private static _tmpdir?: string;
}