forked from SamKirkland/ftp-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocalFiles.ts
43 lines (36 loc) · 1.4 KB
/
localFiles.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
import readdir from "@jsdevtools/readdir-enhanced";
import { Record, IFileList, syncFileDescription, currentSyncFileVersion, IFtpDeployArgumentsWithDefaults } from "./types";
import { fileHash } from "./HashDiff";
import { applyExcludeFilter } from "./utilities";
export async function getLocalFiles(args: IFtpDeployArgumentsWithDefaults): Promise<IFileList> {
const files = await readdir.async(args["local-dir"], { deep: true, stats: true, sep: "/", filter: (stat) => applyExcludeFilter(stat, args.exclude) });
const records: Record[] = [];
for (let stat of files) {
if (stat.isDirectory()) {
records.push({
type: "folder",
name: stat.path,
size: undefined
});
continue;
}
if (stat.isFile()) {
records.push({
type: "file",
name: stat.path,
size: stat.size,
hash: await fileHash(args["local-dir"] + stat.path, "sha256")
});
continue;
}
if (stat.isSymbolicLink()) {
console.warn("This script is currently unable to handle symbolic links - please add a feature request if you need this");
}
}
return {
description: syncFileDescription,
version: currentSyncFileVersion,
generatedTime: new Date().getTime(),
data: records
};
}