-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-utils.ts
More file actions
46 lines (38 loc) · 1.25 KB
/
file-utils.ts
File metadata and controls
46 lines (38 loc) · 1.25 KB
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
import * as fs from "fs";
import * as path from "path";
import * as rimraf from "rimraf";
import * as temp from "temp";
export function isBinaryOrZip(path: string): boolean {
return path.search(/\.zip$/i) !== -1 || path.search(/\.apk$/i) !== -1 || path.search(/\.ipa$/i) !== -1;
}
export function isDirectory(path: string): boolean {
return fs.statSync(path).isDirectory();
}
export function fileExists(file: string): boolean {
try {
return fs.statSync(file).isFile();
} catch (e) {
return false;
}
};
export function copyFileToTmpDir(filePath: string): string {
if (!isDirectory(filePath)) {
const outputFolderPath: string = temp.mkdirSync("code-push");
rimraf.sync(outputFolderPath);
fs.mkdirSync(outputFolderPath);
const outputFilePath: string = path.join(outputFolderPath, path.basename(filePath));
fs.writeFileSync(outputFilePath, fs.readFileSync(filePath));
return outputFolderPath;
}
}
export function fileDoesNotExistOrIsDirectory(path: string): boolean {
try {
return isDirectory(path);
} catch (error) {
return true;
}
}
export function normalizePath(filePath: string): string {
//replace all backslashes coming from cli running on windows machines by slashes
return filePath.replace(/\\/g, "/");
}