refactoring to ts

This commit is contained in:
Benjamin Toby
2025-01-15 05:43:18 +01:00
parent 4c45eba321
commit 222d1a4372
11 changed files with 90 additions and 87 deletions
-1
View File
@@ -9,7 +9,6 @@ const watchFolders = require("./watch/folders");
const confFileProvidedJSON = process.argv[process.argv.length - 1];
try {
/** @type {import("..").TurboSyncConfigObject} */
const configFileObject = JSON.parse(confFileProvidedJSON);
console.log(`Running '${configFileObject.title}' ...`);
+12 -20
View File
@@ -1,19 +1,17 @@
// @ts-check
const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const delay = require("../../utils/delay");
import { execSync } from "child_process";
import fs from "fs";
import delay from "../../utils/delay";
import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types";
/** @type {any} */
let timeout;
let timeout: any;
const UPDATE_TIMEOUT = 2000;
/**
*
* @param {SyncFilesFnParams} param0
*/
async function watchFiles({ files, options }) {
export default async function watchFiles({
files,
options,
}: SyncFilesFnParams) {
try {
for (let i = 0; i < files.length; i++) {
const file = files[i];
@@ -53,7 +51,7 @@ async function watchFiles({ files, options }) {
options,
});
}
} catch (error) {
} catch (error: any) {
throw new Error(
`File Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`
);
@@ -90,17 +88,13 @@ async function watchFiles({ files, options }) {
);
}
}
} catch (error) {
} catch (error: any) {
console.log("ERROR:", error.message);
process.exit(0);
}
}
/**
*
* @param {SyncFilesSyncFnParams} param0
*/
function sync({ options, filePath, files }) {
function sync({ options, filePath, files }: SyncFilesSyncFnParams) {
const destFiles = files.filter((fl) => {
if (typeof fl == "string") return fl !== filePath;
if (fl?.path) return fl.path !== filePath;
@@ -172,5 +166,3 @@ function sync({ options, filePath, files }) {
}
}
}
module.exports = watchFiles;
+13 -20
View File
@@ -1,19 +1,18 @@
// @ts-check
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const delay = require("../../utils/delay");
import fs from "fs";
import path from "path";
import { execSync } from "child_process";
import delay from "../../utils/delay";
import { SyncFoldersFnParams, SyncFoldersSyncFnParams } from "../../types";
/** @type {any} */
let timeout;
let timeout: any;
const UPDATE_TIMEOUT = 2000;
/**
*
* @param {SyncFoldersFnParams} param0
*/
async function watchFolders({ folders, options }) {
export default async function watchFolders({
folders,
options,
}: SyncFoldersFnParams) {
try {
const dirs = folders;
@@ -73,7 +72,7 @@ async function watchFolders({ folders, options }) {
init: true,
});
}
} catch (error) {
} catch (error: any) {
console.log("Error:", error.message);
throw new Error(
@@ -97,17 +96,13 @@ async function watchFolders({ folders, options }) {
});
}
}
} catch (error) {
} catch (error: any) {
console.log("ERROR:", error.message);
process.exit(0);
}
}
/**
*
* @param {SyncFoldersSyncFnParams} param0
*/
function sync({ options, dirs, dirPath, init }) {
function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) {
const dstDirs = dirs.filter((dr) => {
if (typeof dr == "string") return dr !== dirPath;
if (dr?.path) return dr.path !== dirPath;
@@ -179,5 +174,3 @@ function sync({ options, dirs, dirPath, init }) {
}
}
}
module.exports = watchFolders;