This commit is contained in:
Benjamin Toby 2025-07-11 06:49:06 +01:00
parent 68c1074de1
commit 37a314273a
8 changed files with 52 additions and 16 deletions

View File

@ -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
```

View File

@ -16,10 +16,10 @@ exports.default = watchFiles;
const child_process_1 = require("child_process"); const child_process_1 = require("child_process");
const fs_1 = __importDefault(require("fs")); const fs_1 = __importDefault(require("fs"));
const delay_1 = __importDefault(require("../../utils/delay")); const delay_1 = __importDefault(require("../../utils/delay"));
let timeout;
const UPDATE_TIMEOUT = 2000;
function watchFiles(_a) { function watchFiles(_a) {
return __awaiter(this, arguments, void 0, function* ({ files, options, }) { return __awaiter(this, arguments, void 0, function* ({ files, options, }) {
let timeout;
const UPDATE_TIMEOUT = 2000;
try { try {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
const file = files[i]; const file = files[i];

View File

@ -17,10 +17,10 @@ const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path")); const path_1 = __importDefault(require("path"));
const child_process_1 = require("child_process"); const child_process_1 = require("child_process");
const delay_1 = __importDefault(require("../../utils/delay")); const delay_1 = __importDefault(require("../../utils/delay"));
let timeout;
const UPDATE_TIMEOUT = 200;
function watchFolders(_a) { function watchFolders(_a) {
return __awaiter(this, arguments, void 0, function* ({ folders, options, }) { return __awaiter(this, arguments, void 0, function* ({ folders, options, }) {
let timeout;
const UPDATE_TIMEOUT = 200;
try { try {
const dirs = folders; const dirs = folders;
console.log(`Now handling ${dirs.length} Directories`); console.log(`Now handling ${dirs.length} Directories`);
@ -112,8 +112,8 @@ function sync({ options, dirs, dirPath, init }) {
cmdArray.push("--delete"); cmdArray.push("--delete");
} }
if ((_a = options === null || options === void 0 ? void 0 : options.include) === null || _a === void 0 ? void 0 : _a[0]) { if ((_a = options === null || options === void 0 ? void 0 : options.include) === null || _a === void 0 ? void 0 : _a[0]) {
options.include.forEach((excl) => { options.include.forEach((incl) => {
cmdArray.push(`--include='${excl}'`); cmdArray.push(`--include='${incl}'`);
}); });
} }
if ((_b = options === null || options === void 0 ? void 0 : options.exclude) === null || _b === void 0 ? void 0 : _b[0]) { if ((_b = options === null || options === void 0 ? void 0 : options.exclude) === null || _b === void 0 ? void 0 : _b[0]) {

View File

@ -1,3 +1,3 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const testVar = 3; const testVar = 35;

View File

@ -1,3 +1,3 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const testVar = 3; const testVar = 35;

View File

@ -3,13 +3,14 @@ import fs from "fs";
import delay from "../../utils/delay"; import delay from "../../utils/delay";
import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types"; import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types";
let timeout: any;
const UPDATE_TIMEOUT = 2000;
export default async function watchFiles({ export default async function watchFiles({
files, files,
options, options,
}: SyncFilesFnParams) { }: SyncFilesFnParams) {
let timeout: any;
const UPDATE_TIMEOUT = 2000;
try { try {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
const file = files[i]; const file = files[i];

View File

@ -4,15 +4,16 @@ import { execSync } from "child_process";
import delay from "../../utils/delay"; import delay from "../../utils/delay";
import { SyncFoldersFnParams, SyncFoldersSyncFnParams } from "../../types"; import { SyncFoldersFnParams, SyncFoldersSyncFnParams } from "../../types";
let timeout: any;
const UPDATE_TIMEOUT = 200;
export default async function watchFolders({ export default async function watchFolders({
folders, folders,
options, options,
}: SyncFoldersFnParams) { }: SyncFoldersFnParams) {
let timeout: any;
const UPDATE_TIMEOUT = 200;
try { try {
const dirs = folders; const dirs = folders;
console.log(`Now handling ${dirs.length} Directories`); console.log(`Now handling ${dirs.length} Directories`);
@ -86,6 +87,7 @@ export default async function watchFolders({
fs.watch(dirPath, { recursive: true }, (evt, fileName) => { fs.watch(dirPath, { recursive: true }, (evt, fileName) => {
if (global.SYNCING) return; if (global.SYNCING) return;
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(() => { timeout = setTimeout(() => {
@ -117,8 +119,8 @@ function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) {
} }
if (options?.include?.[0]) { if (options?.include?.[0]) {
options.include.forEach((excl) => { options.include.forEach((incl) => {
cmdArray.push(`--include='${excl}'`); cmdArray.push(`--include='${incl}'`);
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/turbosync", "name": "@moduletrace/turbosync",
"version": "1.0.6", "version": "1.0.7",
"module": "dist/index.js", "module": "dist/index.js",
"scripts": { "scripts": {
"start": "node dist/index.js", "start": "node dist/index.js",