62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
#! /usr/bin/env node
|
|
|
|
// @ts-check
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { execSync, spawn } = require("child_process");
|
|
const watchFiles = require("./watch/files");
|
|
const watchFolders = require("./watch/folders");
|
|
|
|
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;
|
|
|
|
console.log("firstFolder", firstFolder);
|
|
console.log("folders", folders);
|
|
|
|
console.log("firstFolder", firstFolder);
|
|
console.log("isFolders", Boolean(folders?.[0]));
|
|
|
|
if (firstFile && files?.[0]) {
|
|
watchFiles({ files, options });
|
|
} else if (firstFolder && folders?.[0]) {
|
|
watchFolders({ folders, options });
|
|
}
|
|
} 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);
|
|
}
|
|
});
|