104 lines
4.6 KiB
JavaScript
104 lines
4.6 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const child_process_1 = require("child_process");
|
|
const files_1 = __importDefault(require("./watch/files"));
|
|
const folders_1 = __importDefault(require("./watch/folders"));
|
|
const get_last_edited_src_1 = __importDefault(require("../utils/get-last-edited-src"));
|
|
const grab_folders_files_string_paths_1 = __importStar(require("../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 = false;
|
|
const REWATCH_TIMEOUT = 1000;
|
|
try {
|
|
const configFileObject = JSON.parse(confFileProvidedJSON);
|
|
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),
|
|
});
|
|
console.log(`Running '${configFileObject.title}' ...`);
|
|
console.log(`Last Updated Path => '${lastUpdated || "N/A"}' ...`);
|
|
if (Array.isArray(configFileObject.files) &&
|
|
Array.isArray(configFileObject.folders)) {
|
|
throw new Error("Choose wither `files` or `folders`. Not both");
|
|
}
|
|
const files = configFileObject === null || configFileObject === void 0 ? void 0 : configFileObject.files;
|
|
const firstFile = files === null || files === void 0 ? void 0 : files[0];
|
|
const folders = configFileObject === null || configFileObject === void 0 ? void 0 : configFileObject.folders;
|
|
const firstFolder = folders === null || folders === void 0 ? void 0 : folders[0];
|
|
const options = configFileObject.options;
|
|
const sortedFoldersByLastUpdated = (folders === null || folders === void 0 ? void 0 : folders[0]) && lastUpdated
|
|
? [
|
|
lastUpdated,
|
|
...((folders === null || folders === void 0 ? void 0 : folders.filter((fl) => (0, grab_folders_files_string_paths_1.fldFileToStr)(fl) !== lastUpdated)) || []),
|
|
]
|
|
: folders;
|
|
const sortedFilesByLastUpdated = (files === null || files === void 0 ? void 0 : files[0]) && lastUpdated
|
|
? [
|
|
lastUpdated,
|
|
...((files === null || files === void 0 ? void 0 : files.filter((fl) => (0, grab_folders_files_string_paths_1.fldFileToStr)(fl) !== lastUpdated)) ||
|
|
[]),
|
|
]
|
|
: files;
|
|
if (firstFile && (sortedFilesByLastUpdated === null || sortedFilesByLastUpdated === void 0 ? void 0 : sortedFilesByLastUpdated[0])) {
|
|
(0, files_1.default)({ files: sortedFilesByLastUpdated, options });
|
|
}
|
|
else if (firstFolder && (sortedFoldersByLastUpdated === null || sortedFoldersByLastUpdated === void 0 ? void 0 : sortedFoldersByLastUpdated[0])) {
|
|
(0, folders_1.default)({ folders: sortedFoldersByLastUpdated, options });
|
|
}
|
|
}
|
|
catch (error) {
|
|
console.log(error);
|
|
process.exit();
|
|
}
|
|
process.on("exit", (code) => {
|
|
if (code == global.SYNC_SUCCESS_EXIT_CODE) {
|
|
const args = process.argv;
|
|
const cmd = args.shift();
|
|
if (cmd) {
|
|
(0, child_process_1.spawn)(cmd, args, {
|
|
stdio: "inherit",
|
|
});
|
|
}
|
|
}
|
|
else {
|
|
process.exit(0);
|
|
}
|
|
});
|