2024-10-16 04:44:48 +00:00
|
|
|
#! /usr/bin/env node
|
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
|
2024-10-16 08:40:21 +00:00
|
|
|
const { spawn } = require("child_process");
|
2024-10-16 07:29:28 +00:00
|
|
|
const watchFiles = require("./watch/files");
|
|
|
|
const watchFolders = require("./watch/folders");
|
2024-10-16 04:44:48 +00:00
|
|
|
|
|
|
|
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
|
|
|
|
|
|
|
try {
|
|
|
|
/** @type {TurboSyncConfigObject} */
|
|
|
|
const configFileObject = JSON.parse(confFileProvidedJSON);
|
|
|
|
|
|
|
|
console.log(`Running '${configFileObject.title}' ...`);
|
|
|
|
|
|
|
|
if (
|
|
|
|
Array.isArray(configFileObject.files) &&
|
|
|
|
Array.isArray(configFileObject.folders)
|
|
|
|
) {
|
|
|
|
throw new Error("Choose wither `files` or `folders`. Not both");
|
|
|
|
}
|
|
|
|
|
|
|
|
const files = configFileObject?.files;
|
|
|
|
const firstFile = files?.[0];
|
|
|
|
const folders = configFileObject?.folders;
|
|
|
|
const firstFolder = folders?.[0];
|
|
|
|
|
|
|
|
const options = configFileObject.options;
|
|
|
|
|
2024-10-16 07:29:28 +00:00
|
|
|
if (firstFile && files?.[0]) {
|
|
|
|
watchFiles({ files, options });
|
2024-10-16 04:44:48 +00:00
|
|
|
} else if (firstFolder && folders?.[0]) {
|
2024-10-16 07:29:28 +00:00
|
|
|
watchFolders({ folders, options });
|
2024-10-16 04:44:48 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on("exit", (code) => {
|
|
|
|
if (code == 1) {
|
|
|
|
const args = process.argv;
|
|
|
|
const cmd = args.shift();
|
|
|
|
if (cmd) {
|
|
|
|
spawn(cmd, args, {
|
|
|
|
stdio: "inherit",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|