diff --git a/dist/lib/sync.js b/dist/lib/sync.js index 31261b7..4ccceaa 100644 --- a/dist/lib/sync.js +++ b/dist/lib/sync.js @@ -51,6 +51,7 @@ try { const lastUpdated = (0, get_last_edited_src_1.default)({ dirs: (0, grab_folders_files_string_paths_1.default)(configFileObject.folders), files: (0, grab_folders_files_string_paths_1.default)(configFileObject.files), + config: configFileObject, }); console.log(`Running '${configFileObject.title}' ...`); console.log(`Last Updated Path => '${lastUpdated || "N/A"}' ...`); diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts index 8432e4a..8d32abe 100644 --- a/dist/types/index.d.ts +++ b/dist/types/index.d.ts @@ -17,6 +17,7 @@ export interface TurboSyncOptions { exclude?: string[]; include?: string[]; interval?: number; + bootstrapLastEdited?: boolean; } export interface SyncFilesFnParams { files: (string | TurboSyncFileObject)[]; diff --git a/dist/utils/get-last-edited-src.d.ts b/dist/utils/get-last-edited-src.d.ts index 03421cf..9905753 100644 --- a/dist/utils/get-last-edited-src.d.ts +++ b/dist/utils/get-last-edited-src.d.ts @@ -1,6 +1,8 @@ +import { TurboSyncConfigObject } from "../types"; type Params = { dirs?: 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 {}; diff --git a/dist/utils/get-last-edited-src.js b/dist/utils/get-last-edited-src.js index bbb0c14..c6628e4 100644 --- a/dist/utils/get-last-edited-src.js +++ b/dist/utils/get-last-edited-src.js @@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getLatestSource; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); -function getLatestSource({ dirs, files, }) { +function getLatestSource({ dirs, files, config, }) { let latestDir = undefined; let latestMtime = 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}`); } } + if (latestDir) { + if (isDirEmptySync(latestDir)) + return undefined; + } return latestDir; } function getLatestDirMtime(dir) { @@ -55,3 +59,7 @@ function getLatestDirMtime(dir) { } return latestMtime; } +function isDirEmptySync(path) { + const files = fs_1.default.readdirSync(path); + return files.length === 0; +} diff --git a/lib/sync.ts b/lib/sync.ts index 4ecb3ca..824d241 100644 --- a/lib/sync.ts +++ b/lib/sync.ts @@ -22,6 +22,7 @@ try { const lastUpdated = getLatestSource({ dirs: fldFileToStrArr(configFileObject.folders), files: fldFileToStrArr(configFileObject.files), + config: configFileObject, }); console.log(`Running '${configFileObject.title}' ...`); diff --git a/push.sh b/push.sh old mode 100755 new mode 100644 diff --git a/types/index.ts b/types/index.ts index 46d30bd..197f255 100644 --- a/types/index.ts +++ b/types/index.ts @@ -20,6 +20,7 @@ export interface TurboSyncOptions { exclude?: string[]; include?: string[]; interval?: number; + bootstrapLastEdited?: boolean; } export interface SyncFilesFnParams { diff --git a/utils/get-last-edited-src.ts b/utils/get-last-edited-src.ts index 9b3974c..38b1aae 100644 --- a/utils/get-last-edited-src.ts +++ b/utils/get-last-edited-src.ts @@ -1,14 +1,17 @@ import fs from "fs"; import path from "path"; +import { TurboSyncConfigObject } from "../types"; type Params = { dirs?: string[]; files?: string[]; + config: TurboSyncConfigObject; }; export default function getLatestSource({ dirs, files, + config, }: Params): string | undefined { let latestDir = undefined; let latestMtime = 0; @@ -35,6 +38,10 @@ export default function getLatestSource({ } } + if (latestDir) { + if (isDirEmptySync(latestDir)) return undefined; + } + return latestDir; } @@ -65,3 +72,8 @@ function getLatestDirMtime(dir: string) { return latestMtime; } + +function isDirEmptySync(path: string) { + const files = fs.readdirSync(path); + return files.length === 0; +}