From 37a314273ae0eccd3cb9451b06ebf53195b20d4a Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Fri, 11 Jul 2025 06:49:06 +0100 Subject: [PATCH] Updates --- README.md | 33 +++++++++++++++++++++++++++++++ dist/lib/watch/files.js | 4 ++-- dist/lib/watch/folders.js | 8 ++++---- dist/test/test-1/folder-1/test.js | 2 +- dist/test/test-1/folder-2/test.js | 2 +- lib/watch/files.ts | 5 +++-- lib/watch/folders.ts | 12 ++++++----- package.json | 2 +- 8 files changed, 52 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4ac9ab6..687d87c 100644 --- a/README.md +++ b/README.md @@ -84,3 +84,36 @@ You can also use environment variables in the config file. Example: } ] ``` + +## System Processes + +Run Turbosync as a system process to keep it running in the background. + +### Systemd Config + +Use this template to create a systemd service for turbosync. + +```ini +[Unit] +Description=Service Name +After=network.target + +[Service] +ExecStart=/home/user/.bun/bin/turbosync +Restart=always +RestartSec=5 +Environment="PATH=/usr/bin:/home/user/.bun/bin:/home/user/.nvm/versions/node/v20.18.1/bin:${PATH}" +User=user +WorkingDirectory=/home/user/services/turbosync/service-name + +[Install] +WantedBy=multi-user.target +``` + +After this you can run: + +```bash +sudo systemctl daemon-reload +sudo systemctl enable turbosync-service-name +sudo systemctl start turbosync-service-name +``` diff --git a/dist/lib/watch/files.js b/dist/lib/watch/files.js index 6c6f3b7..e57a453 100644 --- a/dist/lib/watch/files.js +++ b/dist/lib/watch/files.js @@ -16,10 +16,10 @@ exports.default = watchFiles; const child_process_1 = require("child_process"); const fs_1 = __importDefault(require("fs")); const delay_1 = __importDefault(require("../../utils/delay")); -let timeout; -const UPDATE_TIMEOUT = 2000; function watchFiles(_a) { return __awaiter(this, arguments, void 0, function* ({ files, options, }) { + let timeout; + const UPDATE_TIMEOUT = 2000; try { for (let i = 0; i < files.length; i++) { const file = files[i]; diff --git a/dist/lib/watch/folders.js b/dist/lib/watch/folders.js index 6c11f08..f957037 100644 --- a/dist/lib/watch/folders.js +++ b/dist/lib/watch/folders.js @@ -17,10 +17,10 @@ const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const child_process_1 = require("child_process"); const delay_1 = __importDefault(require("../../utils/delay")); -let timeout; -const UPDATE_TIMEOUT = 200; function watchFolders(_a) { return __awaiter(this, arguments, void 0, function* ({ folders, options, }) { + let timeout; + const UPDATE_TIMEOUT = 200; try { const dirs = folders; console.log(`Now handling ${dirs.length} Directories`); @@ -112,8 +112,8 @@ function sync({ options, dirs, dirPath, init }) { cmdArray.push("--delete"); } if ((_a = options === null || options === void 0 ? void 0 : options.include) === null || _a === void 0 ? void 0 : _a[0]) { - options.include.forEach((excl) => { - cmdArray.push(`--include='${excl}'`); + options.include.forEach((incl) => { + cmdArray.push(`--include='${incl}'`); }); } if ((_b = options === null || options === void 0 ? void 0 : options.exclude) === null || _b === void 0 ? void 0 : _b[0]) { diff --git a/dist/test/test-1/folder-1/test.js b/dist/test/test-1/folder-1/test.js index e2737d0..b9efffe 100644 --- a/dist/test/test-1/folder-1/test.js +++ b/dist/test/test-1/folder-1/test.js @@ -1,3 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const testVar = 3; +const testVar = 35; diff --git a/dist/test/test-1/folder-2/test.js b/dist/test/test-1/folder-2/test.js index e2737d0..b9efffe 100644 --- a/dist/test/test-1/folder-2/test.js +++ b/dist/test/test-1/folder-2/test.js @@ -1,3 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const testVar = 3; +const testVar = 35; diff --git a/lib/watch/files.ts b/lib/watch/files.ts index 1d1e1bc..6e462a0 100644 --- a/lib/watch/files.ts +++ b/lib/watch/files.ts @@ -3,13 +3,14 @@ import fs from "fs"; import delay from "../../utils/delay"; import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types"; -let timeout: any; -const UPDATE_TIMEOUT = 2000; export default async function watchFiles({ files, options, }: SyncFilesFnParams) { + let timeout: any; + const UPDATE_TIMEOUT = 2000; + try { for (let i = 0; i < files.length; i++) { const file = files[i]; diff --git a/lib/watch/folders.ts b/lib/watch/folders.ts index f5146a1..b459a5d 100644 --- a/lib/watch/folders.ts +++ b/lib/watch/folders.ts @@ -4,15 +4,16 @@ import { execSync } from "child_process"; import delay from "../../utils/delay"; import { SyncFoldersFnParams, SyncFoldersSyncFnParams } from "../../types"; -let timeout: any; -const UPDATE_TIMEOUT = 200; export default async function watchFolders({ folders, options, }: SyncFoldersFnParams) { + let timeout: any; + const UPDATE_TIMEOUT = 200; + try { - const dirs = folders; + const dirs = folders; console.log(`Now handling ${dirs.length} Directories`); @@ -86,6 +87,7 @@ export default async function watchFolders({ fs.watch(dirPath, { recursive: true }, (evt, fileName) => { if (global.SYNCING) return; + clearTimeout(timeout); timeout = setTimeout(() => { @@ -117,8 +119,8 @@ function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) { } if (options?.include?.[0]) { - options.include.forEach((excl) => { - cmdArray.push(`--include='${excl}'`); + options.include.forEach((incl) => { + cmdArray.push(`--include='${incl}'`); }); } diff --git a/package.json b/package.json index 3086d21..8f7c314 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/turbosync", - "version": "1.0.6", + "version": "1.0.7", "module": "dist/index.js", "scripts": { "start": "node dist/index.js",