This commit is contained in:
Benjamin Toby 2025-11-20 08:02:54 +01:00
parent 822778d43b
commit fde40e8ece
8 changed files with 28 additions and 2 deletions

1
dist/lib/sync.js vendored
View File

@ -51,6 +51,7 @@ try {
const lastUpdated = (0, get_last_edited_src_1.default)({ const lastUpdated = (0, get_last_edited_src_1.default)({
dirs: (0, grab_folders_files_string_paths_1.default)(configFileObject.folders), dirs: (0, grab_folders_files_string_paths_1.default)(configFileObject.folders),
files: (0, grab_folders_files_string_paths_1.default)(configFileObject.files), files: (0, grab_folders_files_string_paths_1.default)(configFileObject.files),
config: configFileObject,
}); });
console.log(`Running '${configFileObject.title}' ...`); console.log(`Running '${configFileObject.title}' ...`);
console.log(`Last Updated Path => '${lastUpdated || "N/A"}' ...`); console.log(`Last Updated Path => '${lastUpdated || "N/A"}' ...`);

View File

@ -17,6 +17,7 @@ export interface TurboSyncOptions {
exclude?: string[]; exclude?: string[];
include?: string[]; include?: string[];
interval?: number; interval?: number;
bootstrapLastEdited?: boolean;
} }
export interface SyncFilesFnParams { export interface SyncFilesFnParams {
files: (string | TurboSyncFileObject)[]; files: (string | TurboSyncFileObject)[];

View File

@ -1,6 +1,8 @@
import { TurboSyncConfigObject } from "../types";
type Params = { type Params = {
dirs?: string[]; dirs?: string[];
files?: string[]; files?: string[];
config: TurboSyncConfigObject;
}; };
export default function getLatestSource({ dirs, files, }: Params): string | undefined; export default function getLatestSource({ dirs, files, config, }: Params): string | undefined;
export {}; export {};

View File

@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getLatestSource; exports.default = getLatestSource;
const fs_1 = __importDefault(require("fs")); const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path")); const path_1 = __importDefault(require("path"));
function getLatestSource({ dirs, files, }) { function getLatestSource({ dirs, files, config, }) {
let latestDir = undefined; let latestDir = undefined;
let latestMtime = 0; let latestMtime = 0;
const isFiles = files === null || files === void 0 ? void 0 : files[0]; const isFiles = files === null || files === void 0 ? void 0 : files[0];
@ -28,6 +28,10 @@ function getLatestSource({ dirs, files, }) {
console.error(`Error accessing ${pth}: ${error.message}`); console.error(`Error accessing ${pth}: ${error.message}`);
} }
} }
if (latestDir) {
if (isDirEmptySync(latestDir))
return undefined;
}
return latestDir; return latestDir;
} }
function getLatestDirMtime(dir) { function getLatestDirMtime(dir) {
@ -55,3 +59,7 @@ function getLatestDirMtime(dir) {
} }
return latestMtime; return latestMtime;
} }
function isDirEmptySync(path) {
const files = fs_1.default.readdirSync(path);
return files.length === 0;
}

View File

@ -22,6 +22,7 @@ try {
const lastUpdated = getLatestSource({ const lastUpdated = getLatestSource({
dirs: fldFileToStrArr(configFileObject.folders), dirs: fldFileToStrArr(configFileObject.folders),
files: fldFileToStrArr(configFileObject.files), files: fldFileToStrArr(configFileObject.files),
config: configFileObject,
}); });
console.log(`Running '${configFileObject.title}' ...`); console.log(`Running '${configFileObject.title}' ...`);

0
push.sh Executable file → Normal file
View File

View File

@ -20,6 +20,7 @@ export interface TurboSyncOptions {
exclude?: string[]; exclude?: string[];
include?: string[]; include?: string[];
interval?: number; interval?: number;
bootstrapLastEdited?: boolean;
} }
export interface SyncFilesFnParams { export interface SyncFilesFnParams {

View File

@ -1,14 +1,17 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import { TurboSyncConfigObject } from "../types";
type Params = { type Params = {
dirs?: string[]; dirs?: string[];
files?: string[]; files?: string[];
config: TurboSyncConfigObject;
}; };
export default function getLatestSource({ export default function getLatestSource({
dirs, dirs,
files, files,
config,
}: Params): string | undefined { }: Params): string | undefined {
let latestDir = undefined; let latestDir = undefined;
let latestMtime = 0; let latestMtime = 0;
@ -35,6 +38,10 @@ export default function getLatestSource({
} }
} }
if (latestDir) {
if (isDirEmptySync(latestDir)) return undefined;
}
return latestDir; return latestDir;
} }
@ -65,3 +72,8 @@ function getLatestDirMtime(dir: string) {
return latestMtime; return latestMtime;
} }
function isDirEmptySync(path: string) {
const files = fs.readdirSync(path);
return files.length === 0;
}