This commit is contained in:
Benjamin Toby
2025-02-04 13:42:30 +01:00
parent 8a1294a348
commit efcee1bb11
24 changed files with 100 additions and 23 deletions
+3
View File
@@ -1,2 +1,5 @@
#!/usr/bin/env node
declare global {
var SYNCING: boolean;
}
export {};
+1 -1
View File
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const child_process_1 = require("child_process");
const env_1 = __importDefault(require("./utils/env"));
global.SYNCING = false;
const confFileProvidedPath = process.argv[process.argv.length - 1];
if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") {
try {
@@ -47,7 +48,6 @@ try {
if (!configJSON)
throw new Error("Config JSON could not be resolved. Please check your files.");
const parsedConfigJSON = (0, env_1.default)({ json: configJSON });
/** @type {import(".").TurboSyncConfigArray} */
const configArray = JSON.parse(parsedConfigJSON);
for (let i = 0; i < configArray.length; i++) {
const config = configArray[i];
+1
View File
@@ -7,6 +7,7 @@ const child_process_1 = require("child_process");
const files_1 = __importDefault(require("./watch/files"));
const folders_1 = __importDefault(require("./watch/folders"));
const confFileProvidedJSON = process.argv[process.argv.length - 1];
global.SYNCING = false;
try {
const configFileObject = JSON.parse(confFileProvidedJSON);
console.log(`Running '${configFileObject.title}' ...`);
+4 -1
View File
@@ -70,13 +70,16 @@ function watchFiles(_a) {
sync({ options, filePath, files });
yield (0, delay_1.default)();
fs_1.default.watchFile(filePath, {
interval: interval || 500,
interval: interval || 200,
}, (curr, prev) => {
if (global.SYNCING)
return;
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval)
? options.interval
: UPDATE_TIMEOUT;
clearTimeout(timeout);
timeout = setTimeout(() => {
global.SYNCING = true;
sync({ options, filePath, files });
process.exit(1);
}, INTERVAL);
+4 -1
View File
@@ -18,7 +18,7 @@ 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 = 2000;
const UPDATE_TIMEOUT = 200;
function watchFolders(_a) {
return __awaiter(this, arguments, void 0, function* ({ folders, options, }) {
try {
@@ -79,8 +79,11 @@ function watchFolders(_a) {
sync({ dirPath, dirs, options });
yield (0, delay_1.default)();
fs_1.default.watch(dirPath, { recursive: true }, (evt, fileName) => {
if (global.SYNCING)
return;
clearTimeout(timeout);
timeout = setTimeout(() => {
global.SYNCING = true;
sync({ dirPath, dirs, options });
process.exit(1);
}, INTERVAL);
+1
View File
@@ -0,0 +1 @@
export {};
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+1
View File
@@ -0,0 +1 @@
export {};
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+1
View File
@@ -0,0 +1 @@
export {};
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+1
View File
@@ -0,0 +1 @@
export {};
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+6 -6
View File
@@ -1,8 +1,8 @@
export type TurboSyncConfigArray = TurboSyncConfigObject[];
export interface TurboSyncConfigObject {
title?: string;
files?: string[] | TurboSyncFileObject[];
folders?: string[] | TurboSyncFileObject[];
files?: (string | TurboSyncFileObject)[];
folders?: (string | TurboSyncFileObject)[];
options?: TurboSyncOptions;
}
export interface TurboSyncFileObject {
@@ -18,20 +18,20 @@ export interface TurboSyncOptions {
interval?: number;
}
export interface SyncFilesFnParams {
files: string[] | TurboSyncFileObject[];
files: (string | TurboSyncFileObject)[];
options: TurboSyncOptions | undefined;
}
export interface SyncFilesSyncFnParams {
files: string[] | TurboSyncFileObject[];
files: (string | TurboSyncFileObject)[];
options: TurboSyncOptions | undefined;
filePath: string;
}
export interface SyncFoldersFnParams {
folders: string[] | TurboSyncFileObject[];
folders: (string | TurboSyncFileObject)[];
options: TurboSyncOptions | undefined;
}
export interface SyncFoldersSyncFnParams {
dirs: string[] | TurboSyncFileObject[];
dirs: (string | TurboSyncFileObject)[];
options: TurboSyncOptions | undefined;
dirPath: string;
init?: boolean;
+1 -1
View File
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = delay;
function delay() {
return __awaiter(this, arguments, void 0, function* (time = 500) {
return __awaiter(this, arguments, void 0, function* (time = 200) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);