This commit is contained in:
Benjamin Toby
2024-10-16 12:39:14 +01:00
parent 9518efef8a
commit f2892f1bf4
5 changed files with 80 additions and 33 deletions
+32 -14
View File
@@ -5,6 +5,10 @@ const fs = require("fs");
const path = require("path");
const delay = require("../../utils/delay");
/** @type {any} */
let timeout;
const UPDATE_TIMEOUT = 2000;
/**
*
* @param {SyncFilesFnParams} param0
@@ -72,8 +76,16 @@ async function watchFiles({ files, options }) {
interval: interval || 500,
},
(curr, prev) => {
sync({ options, filePath, files });
process.exit(1);
const INTERVAL = options?.interval
? options.interval
: UPDATE_TIMEOUT;
clearTimeout(timeout);
timeout = setTimeout(() => {
sync({ options, filePath, files });
process.exit(1);
}, INTERVAL);
}
);
}
@@ -89,18 +101,6 @@ async function watchFiles({ files, options }) {
* @param {SyncFilesSyncFnParams} param0
*/
function sync({ options, filePath, files }) {
let cmdArray = ["rsync", "-avh"];
if (options?.delete) {
cmdArray.push("--delete");
}
if (options?.exclude?.[0]) {
options.exclude.forEach((excl) => {
cmdArray.push(`--exclude '${excl}'`);
});
}
const destFiles = files.filter((fl) => {
if (typeof fl == "string") return fl !== filePath;
if (fl?.path) return fl.path !== filePath;
@@ -108,6 +108,18 @@ function sync({ options, filePath, files }) {
});
for (let j = 0; j < destFiles.length; j++) {
let cmdArray = ["rsync", "-avh"];
if (options?.delete) {
cmdArray.push("--delete");
}
if (options?.exclude?.[0]) {
options.exclude.forEach((excl) => {
cmdArray.push(`--exclude '${excl}'`);
});
}
const dstFl = destFiles[j];
if (typeof dstFl == "string") {
if (!fs.existsSync(dstFl)) continue;
@@ -121,6 +133,8 @@ function sync({ options, filePath, files }) {
cmdArray.push(filePath, dstFl);
const cmd = cmdArray.join(" ");
console.log(`Running cmd 1 => ${cmd}`);
execSync(cmd, {
stdio: "inherit",
});
@@ -146,7 +160,11 @@ function sync({ options, filePath, files }) {
});
} else {
cmdArray.push(filePath, dstFl.path);
const cmd = cmdArray.join(" ");
console.log(`Running cmd 2 => ${cmd}`);
execSync(cmd, {
stdio: "inherit",
});
+16 -14
View File
@@ -7,7 +7,7 @@ const delay = require("../../utils/delay");
/** @type {any} */
let timeout;
const UPDATE_TIMEOUT = 1000;
const UPDATE_TIMEOUT = 2000;
/**
*
@@ -19,6 +19,8 @@ async function watchFolders({ folders, options }) {
console.log(`Now handling ${dirs.length} Directories`);
const INTERVAL = options?.interval ? options.interval : UPDATE_TIMEOUT;
for (let i = 0; i < dirs.length; i++) {
const dir = dirs[i];
@@ -91,7 +93,7 @@ async function watchFolders({ folders, options }) {
timeout = setTimeout(() => {
sync({ dirPath, dirs, options });
process.exit(1);
}, UPDATE_TIMEOUT);
}, INTERVAL);
});
}
}
@@ -106,18 +108,6 @@ async function watchFolders({ folders, options }) {
* @param {SyncFoldersSyncFnParams} param0
*/
function sync({ options, dirs, dirPath, init }) {
let cmdArray = ["rsync", "-avh"];
if (options?.delete) {
cmdArray.push("--delete");
}
if (options?.exclude?.[0]) {
options.exclude.forEach((excl) => {
cmdArray.push(`--exclude '${excl}'`);
});
}
const dstDirs = dirs.filter((dr) => {
if (typeof dr == "string") return dr !== dirPath;
if (dr?.path) return dr.path !== dirPath;
@@ -125,6 +115,18 @@ function sync({ options, dirs, dirPath, init }) {
});
for (let j = 0; j < dstDirs.length; j++) {
let cmdArray = ["rsync", "-avh"];
if (options?.delete) {
cmdArray.push("--delete");
}
if (options?.exclude?.[0]) {
options.exclude.forEach((excl) => {
cmdArray.push(`--exclude '${excl}'`);
});
}
const dstDr = dstDirs[j];
if (typeof dstDr == "string") {
if (!fs.existsSync(dstDr)) continue;