You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
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
|
|
};
|
|
}
|