Updates
This commit is contained in:
+36
-13
@@ -1,25 +1,31 @@
|
||||
import fs from "fs";
|
||||
import { spawn } from "child_process";
|
||||
import watchFiles from "./watch/files";
|
||||
import watchFolders from "./watch/folders";
|
||||
import { TurboSyncConfigObject } from "../types";
|
||||
import path from "path";
|
||||
import getLatestSource from "../utils/get-last-edited-src";
|
||||
import fldFileToStrArr, {
|
||||
fldFileToStr,
|
||||
} from "../utils/grab-folders-files-string-paths";
|
||||
|
||||
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
||||
|
||||
global.SYNC_SUCCESS_EXIT_CODE = 32;
|
||||
global.CONFIG_DIR = process.cwd();
|
||||
global.SYNCING_FILE = path.join(global.CONFIG_DIR, "syncing.txt");
|
||||
global.SYNCING = false;
|
||||
|
||||
const REWATCH_TIMEOUT = 1000;
|
||||
|
||||
try {
|
||||
if (fs.existsSync(global.SYNCING_FILE)) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const configFileObject: TurboSyncConfigObject =
|
||||
JSON.parse(confFileProvidedJSON);
|
||||
|
||||
const lastUpdated = getLatestSource({
|
||||
dirs: fldFileToStrArr(configFileObject.folders),
|
||||
files: fldFileToStrArr(configFileObject.files),
|
||||
});
|
||||
|
||||
console.log(`Running '${configFileObject.title}' ...`);
|
||||
console.log(`Last Updated Path => '${lastUpdated || "N/A"}' ...`);
|
||||
|
||||
if (
|
||||
Array.isArray(configFileObject.files) &&
|
||||
@@ -35,10 +41,29 @@ try {
|
||||
|
||||
const options = configFileObject.options;
|
||||
|
||||
if (firstFile && files?.[0]) {
|
||||
watchFiles({ files, options });
|
||||
} else if (firstFolder && folders?.[0]) {
|
||||
watchFolders({ folders, options });
|
||||
const sortedFoldersByLastUpdated =
|
||||
folders?.[0] && lastUpdated
|
||||
? [
|
||||
lastUpdated,
|
||||
...(folders?.filter(
|
||||
(fl) => fldFileToStr(fl) !== lastUpdated
|
||||
) || []),
|
||||
]
|
||||
: folders;
|
||||
|
||||
const sortedFilesByLastUpdated =
|
||||
files?.[0] && lastUpdated
|
||||
? [
|
||||
lastUpdated,
|
||||
...(files?.filter((fl) => fldFileToStr(fl) !== lastUpdated) ||
|
||||
[]),
|
||||
]
|
||||
: files;
|
||||
|
||||
if (firstFile && sortedFilesByLastUpdated?.[0]) {
|
||||
watchFiles({ files: sortedFilesByLastUpdated, options });
|
||||
} else if (firstFolder && sortedFoldersByLastUpdated?.[0]) {
|
||||
watchFolders({ folders: sortedFoldersByLastUpdated, options });
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -47,8 +72,6 @@ try {
|
||||
|
||||
process.on("exit", (code) => {
|
||||
if (code == global.SYNC_SUCCESS_EXIT_CODE) {
|
||||
fs.unlinkSync(global.SYNCING_FILE);
|
||||
|
||||
const args = process.argv;
|
||||
const cmd = args.shift();
|
||||
if (cmd) {
|
||||
|
||||
Reference in New Issue
Block a user