Updates
This commit is contained in:
parent
222d1a4372
commit
219db3d88e
2
dist/index.d.ts
vendored
Normal file
2
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
export {};
|
70
dist/index.js
vendored
Normal file
70
dist/index.js
vendored
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#! /usr/bin/env node
|
||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const fs_1 = __importDefault(require("fs"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const child_process_1 = require("child_process");
|
||||||
|
const env_1 = __importDefault(require("./utils/env"));
|
||||||
|
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
||||||
|
if (confFileProvidedPath === "--version" || confFileProvidedPath === "-v") {
|
||||||
|
try {
|
||||||
|
const packageJson = fs_1.default.readFileSync(path_1.default.resolve(__dirname, "package.json"), "utf8");
|
||||||
|
console.log(`Turbo Sync Version: ${JSON.parse(packageJson).version}`);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Turbo Sync Version fetch failed! \nNo Worries, Turbo Sync is still installed properly");
|
||||||
|
}
|
||||||
|
process.exit(6);
|
||||||
|
}
|
||||||
|
console.log("Running Folder Sync ...");
|
||||||
|
const defaultConfigFilePath = path_1.default.resolve(process.cwd(), "turbosync.config.json");
|
||||||
|
const confFileComputedPath = typeof confFileProvidedPath == "string" &&
|
||||||
|
confFileProvidedPath.endsWith(".json")
|
||||||
|
? path_1.default.resolve(process.cwd(), confFileProvidedPath)
|
||||||
|
: null;
|
||||||
|
if (!fs_1.default.existsSync(defaultConfigFilePath) && !confFileComputedPath) {
|
||||||
|
console.log("Please Provide the path to a config file or add a config file named `turbosync.config.json` to the path you're running this program");
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
if (!defaultConfigFilePath &&
|
||||||
|
confFileComputedPath &&
|
||||||
|
!fs_1.default.existsSync(confFileComputedPath)) {
|
||||||
|
console.log("Config File does not exist");
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const configFinalPath = fs_1.default.existsSync(defaultConfigFilePath)
|
||||||
|
? defaultConfigFilePath
|
||||||
|
: confFileComputedPath && fs_1.default.existsSync(confFileComputedPath)
|
||||||
|
? confFileComputedPath
|
||||||
|
: null;
|
||||||
|
const configJSON = configFinalPath
|
||||||
|
? fs_1.default.readFileSync(configFinalPath, "utf8")
|
||||||
|
: null;
|
||||||
|
if (!configJSON)
|
||||||
|
throw new Error("Config JSON could not be resolved. Please check your files.");
|
||||||
|
const parsedConfigJSON = (0, env_1.default)({ json: configJSON });
|
||||||
|
/** @type {import(".").TurboSyncConfigArray} */
|
||||||
|
const configArray = JSON.parse(parsedConfigJSON);
|
||||||
|
for (let i = 0; i < configArray.length; i++) {
|
||||||
|
const config = configArray[i];
|
||||||
|
console.log(`Syncing \`${config.title} ...\``);
|
||||||
|
const childProcess = (0, child_process_1.spawn)("node", [
|
||||||
|
path_1.default.resolve(__dirname, "./lib/sync.js"),
|
||||||
|
`${JSON.stringify(config)}`,
|
||||||
|
], {
|
||||||
|
stdio: "inherit",
|
||||||
|
detached: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(`Process Error =>`, error.message);
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
setInterval(() => {
|
||||||
|
console.log(`Turbo Sync Running for ${process.uptime().toLocaleString()}s ...`);
|
||||||
|
}, 60000);
|
1
dist/lib/sync.d.ts
vendored
Normal file
1
dist/lib/sync.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export {};
|
46
dist/lib/sync.js
vendored
Normal file
46
dist/lib/sync.js
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
"use strict";
|
||||||
|
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 confFileProvidedJSON = process.argv[process.argv.length - 1];
|
||||||
|
try {
|
||||||
|
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 === 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;
|
||||||
|
if (firstFile && (files === null || files === void 0 ? void 0 : files[0])) {
|
||||||
|
(0, files_1.default)({ files, options });
|
||||||
|
}
|
||||||
|
else if (firstFolder && (folders === null || folders === void 0 ? void 0 : folders[0])) {
|
||||||
|
(0, folders_1.default)({ 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) {
|
||||||
|
(0, child_process_1.spawn)(cmd, args, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
2
dist/lib/watch/files.d.ts
vendored
Normal file
2
dist/lib/watch/files.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import { SyncFilesFnParams } from "../../types";
|
||||||
|
export default function watchFiles({ files, options, }: SyncFilesFnParams): Promise<void>;
|
152
dist/lib/watch/files.js
vendored
Normal file
152
dist/lib/watch/files.js
vendored
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = watchFiles;
|
||||||
|
const child_process_1 = require("child_process");
|
||||||
|
const fs_1 = __importDefault(require("fs"));
|
||||||
|
const delay_1 = __importDefault(require("../../utils/delay"));
|
||||||
|
let timeout;
|
||||||
|
const UPDATE_TIMEOUT = 2000;
|
||||||
|
function watchFiles(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ files, options, }) {
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
const file = files[i];
|
||||||
|
const filePath = typeof file == "string" ? file : (file === null || file === void 0 ? void 0 : file.path) ? file.path : null;
|
||||||
|
const interval = typeof file == "object" ? file.interval : null;
|
||||||
|
if (!filePath)
|
||||||
|
continue;
|
||||||
|
if (typeof file == "string" && !fs_1.default.existsSync(filePath)) {
|
||||||
|
try {
|
||||||
|
const existingFilePath = files.find((fl) => {
|
||||||
|
if (typeof fl == "string")
|
||||||
|
return fs_1.default.existsSync(fl);
|
||||||
|
if (!fl.host)
|
||||||
|
return fs_1.default.existsSync(fl.path); // TODO handle remote
|
||||||
|
});
|
||||||
|
if (!existingFilePath) {
|
||||||
|
throw new Error("No existing Files for reference");
|
||||||
|
}
|
||||||
|
const fileDirPath = typeof existingFilePath == "string"
|
||||||
|
? existingFilePath
|
||||||
|
: existingFilePath.path;
|
||||||
|
if (!fs_1.default.existsSync(fileDirPath)) {
|
||||||
|
fs_1.default.mkdirSync(fileDirPath, { recursive: true });
|
||||||
|
}
|
||||||
|
fs_1.default.writeFileSync(filePath, "");
|
||||||
|
if (typeof existingFilePath == "string") {
|
||||||
|
sync({ filePath: existingFilePath, files, options });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sync({
|
||||||
|
filePath: existingFilePath.path,
|
||||||
|
files,
|
||||||
|
options,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
throw new Error(`File Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof file == "string" && !fs_1.default.statSync(filePath).isFile()) {
|
||||||
|
throw new Error(`'${filePath}' is not a File!`);
|
||||||
|
}
|
||||||
|
if (typeof file == "object" && file.host) {
|
||||||
|
// TODO Handle SSH
|
||||||
|
}
|
||||||
|
else if (typeof file == "string") {
|
||||||
|
sync({ options, filePath, files });
|
||||||
|
yield (0, delay_1.default)();
|
||||||
|
fs_1.default.watchFile(filePath, {
|
||||||
|
interval: interval || 500,
|
||||||
|
}, (curr, prev) => {
|
||||||
|
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval)
|
||||||
|
? options.interval
|
||||||
|
: UPDATE_TIMEOUT;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
sync({ options, filePath, files });
|
||||||
|
process.exit(1);
|
||||||
|
}, INTERVAL);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("ERROR:", error.message);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function sync({ options, filePath, files }) {
|
||||||
|
var _a;
|
||||||
|
const destFiles = files.filter((fl) => {
|
||||||
|
if (typeof fl == "string")
|
||||||
|
return fl !== filePath;
|
||||||
|
if (fl === null || fl === void 0 ? void 0 : fl.path)
|
||||||
|
return fl.path !== filePath;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
for (let j = 0; j < destFiles.length; j++) {
|
||||||
|
let cmdArray = ["rsync", "-avh"];
|
||||||
|
if (options === null || options === void 0 ? void 0 : options.delete) {
|
||||||
|
cmdArray.push("--delete");
|
||||||
|
}
|
||||||
|
if ((_a = options === null || options === void 0 ? void 0 : options.exclude) === null || _a === void 0 ? void 0 : _a[0]) {
|
||||||
|
options.exclude.forEach((excl) => {
|
||||||
|
cmdArray.push(`--exclude '${excl}'`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const dstFl = destFiles[j];
|
||||||
|
if (typeof dstFl == "string") {
|
||||||
|
if (!fs_1.default.existsSync(dstFl))
|
||||||
|
continue;
|
||||||
|
if (filePath === dstFl) {
|
||||||
|
console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`);
|
||||||
|
process.exit(6);
|
||||||
|
}
|
||||||
|
cmdArray.push(filePath, dstFl);
|
||||||
|
const cmd = cmdArray.join(" ");
|
||||||
|
console.log(`Running cmd 1 => ${cmd}`);
|
||||||
|
(0, child_process_1.execSync)(cmd, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (dstFl.path) {
|
||||||
|
if (!dstFl.host && !fs_1.default.existsSync(dstFl.path))
|
||||||
|
continue;
|
||||||
|
if (filePath === dstFl.path) {
|
||||||
|
console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`);
|
||||||
|
process.exit(6);
|
||||||
|
}
|
||||||
|
if (dstFl.host && dstFl.ssh_key && dstFl.user) {
|
||||||
|
cmdArray.push("-e", `'ssh -i ${dstFl.ssh_key}'`);
|
||||||
|
cmdArray.push(filePath, `${dstFl.user}@${dstFl.host}:${dstFl.path}`);
|
||||||
|
const cmd = cmdArray.join(" ");
|
||||||
|
(0, child_process_1.execSync)(cmd, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cmdArray.push(filePath, dstFl.path);
|
||||||
|
const cmd = cmdArray.join(" ");
|
||||||
|
console.log(`Running cmd 2 => ${cmd}`);
|
||||||
|
(0, child_process_1.execSync)(cmd, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
dist/lib/watch/folders.d.ts
vendored
Normal file
2
dist/lib/watch/folders.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import { SyncFoldersFnParams } from "../../types";
|
||||||
|
export default function watchFolders({ folders, options, }: SyncFoldersFnParams): Promise<void>;
|
154
dist/lib/watch/folders.js
vendored
Normal file
154
dist/lib/watch/folders.js
vendored
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = watchFolders;
|
||||||
|
const fs_1 = __importDefault(require("fs"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
const child_process_1 = require("child_process");
|
||||||
|
const delay_1 = __importDefault(require("../../utils/delay"));
|
||||||
|
let timeout;
|
||||||
|
const UPDATE_TIMEOUT = 2000;
|
||||||
|
function watchFolders(_a) {
|
||||||
|
return __awaiter(this, arguments, void 0, function* ({ folders, options, }) {
|
||||||
|
try {
|
||||||
|
const dirs = folders;
|
||||||
|
console.log(`Now handling ${dirs.length} Directories`);
|
||||||
|
const INTERVAL = (options === null || options === void 0 ? void 0 : options.interval) ? options.interval : UPDATE_TIMEOUT;
|
||||||
|
for (let i = 0; i < dirs.length; i++) {
|
||||||
|
const dir = dirs[i];
|
||||||
|
if (!dir) {
|
||||||
|
console.log(`Dir: ${dir} doesn't exist`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const dirPath = typeof dir == "string" ? dir : dir.path;
|
||||||
|
if ((typeof dir == "string" && !fs_1.default.existsSync(dirPath)) ||
|
||||||
|
(typeof dir == "object" &&
|
||||||
|
dir.path &&
|
||||||
|
!dir.host &&
|
||||||
|
!fs_1.default.existsSync(dir.path))) {
|
||||||
|
console.log(`Dir ${dirPath} does not exist. Creating ...`);
|
||||||
|
try {
|
||||||
|
const existingDirPath = dirs.find((dr) => {
|
||||||
|
if (typeof dr == "string")
|
||||||
|
return fs_1.default.existsSync(dr);
|
||||||
|
if (!dr.host)
|
||||||
|
return fs_1.default.existsSync(dr.path); // TODO handle remote
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
console.log(`Existing Dir to clone: ${existingDirPath}`);
|
||||||
|
if (!existingDirPath) {
|
||||||
|
throw new Error("No existing Directories for reference");
|
||||||
|
}
|
||||||
|
fs_1.default.mkdirSync(dirPath, {
|
||||||
|
recursive: true,
|
||||||
|
});
|
||||||
|
if (typeof existingDirPath == "string") {
|
||||||
|
sync({
|
||||||
|
dirPath: existingDirPath,
|
||||||
|
dirs,
|
||||||
|
options,
|
||||||
|
init: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sync({
|
||||||
|
dirPath: existingDirPath.path,
|
||||||
|
dirs,
|
||||||
|
options,
|
||||||
|
init: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Error:", error.message);
|
||||||
|
throw new Error(`Folder Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof dir == "string") {
|
||||||
|
sync({ dirPath, dirs, options });
|
||||||
|
yield (0, delay_1.default)();
|
||||||
|
fs_1.default.watch(dirPath, { recursive: true }, (evt, fileName) => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
sync({ dirPath, dirs, options });
|
||||||
|
process.exit(1);
|
||||||
|
}, INTERVAL);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("ERROR:", error.message);
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function sync({ options, dirs, dirPath, init }) {
|
||||||
|
var _a;
|
||||||
|
const dstDirs = dirs.filter((dr) => {
|
||||||
|
if (typeof dr == "string")
|
||||||
|
return dr !== dirPath;
|
||||||
|
if (dr === null || dr === void 0 ? void 0 : dr.path)
|
||||||
|
return dr.path !== dirPath;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
for (let j = 0; j < dstDirs.length; j++) {
|
||||||
|
let cmdArray = ["rsync", "-avh"];
|
||||||
|
if (options === null || options === void 0 ? void 0 : options.delete) {
|
||||||
|
cmdArray.push("--delete");
|
||||||
|
}
|
||||||
|
if ((_a = options === null || options === void 0 ? void 0 : options.exclude) === null || _a === void 0 ? void 0 : _a[0]) {
|
||||||
|
options.exclude.forEach((excl) => {
|
||||||
|
cmdArray.push(`--exclude '${excl}'`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const dstDr = dstDirs[j];
|
||||||
|
if (typeof dstDr == "string") {
|
||||||
|
if (!fs_1.default.existsSync(dstDr))
|
||||||
|
continue;
|
||||||
|
if (dirPath === dstDr) {
|
||||||
|
console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`);
|
||||||
|
process.exit(6);
|
||||||
|
}
|
||||||
|
cmdArray.push(path_1.default.normalize(dirPath) + "/", path_1.default.normalize(dstDr) + "/");
|
||||||
|
const cmd = cmdArray.join(" ");
|
||||||
|
(0, child_process_1.execSync)(cmd, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (dstDr.path) {
|
||||||
|
if (!dstDr.host && !fs_1.default.existsSync(dstDr.path))
|
||||||
|
continue;
|
||||||
|
if (dirPath === dstDr.path) {
|
||||||
|
console.log(`You can't sync the same paths. Please check your configuration and resolve duplicate paths`);
|
||||||
|
process.exit(6);
|
||||||
|
}
|
||||||
|
if (dstDr.host && dstDr.ssh_key && dstDr.user) {
|
||||||
|
cmdArray.push("-e", `'ssh -i ${dstDr.ssh_key}'`);
|
||||||
|
cmdArray.push(path_1.default.normalize(dirPath) + "/", `${dstDr.user}@${dstDr.host}:${dstDr.path}/`);
|
||||||
|
const cmd = cmdArray.join(" ");
|
||||||
|
(0, child_process_1.execSync)(cmd, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cmdArray.push(path_1.default.normalize(dirPath), path_1.default.normalize(dstDr.path));
|
||||||
|
const cmd = cmdArray.join(" ");
|
||||||
|
(0, child_process_1.execSync)(cmd, {
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
dist/types/index.d.ts
vendored
Normal file
41
dist/types/index.d.ts
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
export type TurboSyncConfigArray = TurboSyncConfigObject[];
|
||||||
|
export interface TurboSyncConfigObject {
|
||||||
|
title?: string;
|
||||||
|
files?: string[] | TurboSyncFileObject[];
|
||||||
|
folders?: string[] | TurboSyncFileObject[];
|
||||||
|
options?: TurboSyncOptions;
|
||||||
|
}
|
||||||
|
export interface TurboSyncFileObject {
|
||||||
|
path: string;
|
||||||
|
host?: string;
|
||||||
|
user?: string;
|
||||||
|
ssh_key?: string;
|
||||||
|
interval?: number;
|
||||||
|
}
|
||||||
|
export interface TurboSyncOptions {
|
||||||
|
delete?: boolean;
|
||||||
|
exclude?: string[];
|
||||||
|
interval?: number;
|
||||||
|
}
|
||||||
|
export interface SyncFilesFnParams {
|
||||||
|
files: string[] | TurboSyncFileObject[];
|
||||||
|
options: TurboSyncOptions | undefined;
|
||||||
|
}
|
||||||
|
export interface SyncFilesSyncFnParams {
|
||||||
|
files: string[] | TurboSyncFileObject[];
|
||||||
|
options: TurboSyncOptions | undefined;
|
||||||
|
filePath: string;
|
||||||
|
}
|
||||||
|
export interface SyncFoldersFnParams {
|
||||||
|
folders: string[] | TurboSyncFileObject[];
|
||||||
|
options: TurboSyncOptions | undefined;
|
||||||
|
}
|
||||||
|
export interface SyncFoldersSyncFnParams {
|
||||||
|
dirs: string[] | TurboSyncFileObject[];
|
||||||
|
options: TurboSyncOptions | undefined;
|
||||||
|
dirPath: string;
|
||||||
|
init?: boolean;
|
||||||
|
}
|
||||||
|
export interface HandleEnvVarsFnParams {
|
||||||
|
json: string;
|
||||||
|
}
|
2
dist/types/index.js
vendored
Normal file
2
dist/types/index.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
dist/utils/console-colors.d.ts
vendored
Normal file
3
dist/utils/console-colors.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
declare const colorsArr: readonly ["red", "bright", "dim", "underscore", "blink", "reverse", "hidden", "black", "green", "yellow", "blue", "magenta", "cyan", "white", "gray"];
|
||||||
|
export default function colors(text: string, type: (typeof colorsArr)[number], bg: boolean): string;
|
||||||
|
export {};
|
67
dist/utils/console-colors.js
vendored
Normal file
67
dist/utils/console-colors.js
vendored
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = colors;
|
||||||
|
const colorsArr = [
|
||||||
|
"red",
|
||||||
|
"bright",
|
||||||
|
"dim",
|
||||||
|
"underscore",
|
||||||
|
"blink",
|
||||||
|
"reverse",
|
||||||
|
"hidden",
|
||||||
|
"black",
|
||||||
|
"green",
|
||||||
|
"yellow",
|
||||||
|
"blue",
|
||||||
|
"magenta",
|
||||||
|
"cyan",
|
||||||
|
"white",
|
||||||
|
"gray",
|
||||||
|
];
|
||||||
|
const colorCodes = {
|
||||||
|
Reset: "\x1b[0m",
|
||||||
|
Bright: "\x1b[1m",
|
||||||
|
Dim: "\x1b[2m",
|
||||||
|
Underscore: "\x1b[4m",
|
||||||
|
Blink: "\x1b[5m",
|
||||||
|
Reverse: "\x1b[7m",
|
||||||
|
Hidden: "\x1b[8m",
|
||||||
|
FgBlack: "\x1b[30m",
|
||||||
|
FgRed: "\x1b[31m",
|
||||||
|
FgGreen: "\x1b[32m",
|
||||||
|
FgYellow: "\x1b[33m",
|
||||||
|
FgBlue: "\x1b[34m",
|
||||||
|
FgMagenta: "\x1b[35m",
|
||||||
|
FgCyan: "\x1b[36m",
|
||||||
|
FgWhite: "\x1b[37m",
|
||||||
|
FgGray: "\x1b[90m",
|
||||||
|
BgBlack: "\x1b[40m",
|
||||||
|
BgRed: "\x1b[41m",
|
||||||
|
BgGreen: "\x1b[42m",
|
||||||
|
BgYellow: "\x1b[43m",
|
||||||
|
BgBlue: "\x1b[44m",
|
||||||
|
BgMagenta: "\x1b[45m",
|
||||||
|
BgCyan: "\x1b[46m",
|
||||||
|
BgWhite: "\x1b[47m",
|
||||||
|
BgGray: "\x1b[100m",
|
||||||
|
};
|
||||||
|
function colors(text, type, bg) {
|
||||||
|
let finalText = ``;
|
||||||
|
switch (type) {
|
||||||
|
case "red":
|
||||||
|
finalText += bg ? colorCodes.BgRed : colorCodes.FgRed;
|
||||||
|
break;
|
||||||
|
case "green":
|
||||||
|
finalText += bg ? colorCodes.BgGreen : colorCodes.FgGreen;
|
||||||
|
break;
|
||||||
|
case "blue":
|
||||||
|
finalText += bg ? colorCodes.BgBlue : colorCodes.FgBlue;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finalText += colorCodes.Bright;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
finalText += `${text}${colorCodes.Reset}`;
|
||||||
|
console.log("finalText", finalText);
|
||||||
|
return finalText;
|
||||||
|
}
|
1
dist/utils/delay.d.ts
vendored
Normal file
1
dist/utils/delay.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default function delay(time?: number): Promise<unknown>;
|
21
dist/utils/delay.js
vendored
Normal file
21
dist/utils/delay.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = delay;
|
||||||
|
function delay() {
|
||||||
|
return __awaiter(this, arguments, void 0, function* (time = 500) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve(true);
|
||||||
|
}, time);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
2
dist/utils/env.d.ts
vendored
Normal file
2
dist/utils/env.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import { HandleEnvVarsFnParams } from "../types";
|
||||||
|
export default function handleEnvVars({ json }: HandleEnvVarsFnParams): string;
|
42
dist/utils/env.js
vendored
Normal file
42
dist/utils/env.js
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
"use strict";
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.default = handleEnvVars;
|
||||||
|
const fs_1 = __importDefault(require("fs"));
|
||||||
|
const path_1 = __importDefault(require("path"));
|
||||||
|
function handleEnvVars({ json }) {
|
||||||
|
let newJson = json;
|
||||||
|
try {
|
||||||
|
let envVars = Object.assign({}, process.env);
|
||||||
|
const localEnvFilePath = path_1.default.resolve(process.cwd(), "./.env");
|
||||||
|
if (fs_1.default.existsSync(localEnvFilePath)) {
|
||||||
|
const localEnvText = fs_1.default.readFileSync(localEnvFilePath, "utf8");
|
||||||
|
const localEnvKeyPairArray = localEnvText
|
||||||
|
.split("\n")
|
||||||
|
.filter((keyPair) => keyPair &&
|
||||||
|
keyPair.match(/.{3,}/) &&
|
||||||
|
!keyPair.match(/^\#/))
|
||||||
|
.map((keyPair) => keyPair.trim());
|
||||||
|
localEnvKeyPairArray.forEach((keyPair) => {
|
||||||
|
let keyPairArray = keyPair.split("=");
|
||||||
|
const key = keyPairArray.shift();
|
||||||
|
const value = keyPairArray.join("=");
|
||||||
|
if (!key)
|
||||||
|
return;
|
||||||
|
const newEnvObject = {};
|
||||||
|
newEnvObject[key] = value;
|
||||||
|
envVars = Object.assign(Object.assign({}, envVars), newEnvObject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let key in envVars) {
|
||||||
|
newJson = newJson.replaceAll(`$${key}`, String(envVars[key]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(`Error replacing Environment variables`, error.message);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
return newJson;
|
||||||
|
}
|
1
index.ts
1
index.ts
@ -1,5 +1,4 @@
|
|||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
10
lib/sync.ts
10
lib/sync.ts
@ -1,10 +1,6 @@
|
|||||||
#! /usr/bin/env node
|
import { spawn } from "child_process";
|
||||||
|
import watchFiles from "./watch/files";
|
||||||
// @ts-check
|
import watchFolders from "./watch/folders";
|
||||||
|
|
||||||
const { spawn } = require("child_process");
|
|
||||||
const watchFiles = require("./watch/files");
|
|
||||||
const watchFolders = require("./watch/folders");
|
|
||||||
|
|
||||||
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
const confFileProvidedJSON = process.argv[process.argv.length - 1];
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @ts-check
|
|
||||||
|
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import delay from "../../utils/delay";
|
import delay from "../../utils/delay";
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @ts-check
|
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/turbosync",
|
"name": "@moduletrace/turbosync",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"module": "index.js",
|
"module": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.ts",
|
"start": "node dist/index.js",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"compile": "bun build index.js --compile --outfile bin/turbosync",
|
"compile": "bun build index.ts --compile --outfile bin/turbosync",
|
||||||
"dev": "node index.js --watch"
|
"dev": "node index.js --watch"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"turbosync": "./index.js"
|
"turbosync": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"description": "Sync files and directories with ease",
|
"description": "Sync files and directories with ease",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
4
publish.sh
Normal file → Executable file
4
publish.sh
Normal file → Executable file
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
tsc
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
msg="Updates"
|
msg="Updates"
|
||||||
else
|
else
|
||||||
@ -9,4 +11,4 @@ fi
|
|||||||
git add .
|
git add .
|
||||||
git commit -m "$msg"
|
git commit -m "$msg"
|
||||||
git push
|
git push
|
||||||
npm publish
|
bun publish
|
||||||
|
11
push.sh
Executable file
11
push.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
msg="Updates"
|
||||||
|
else
|
||||||
|
msg="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
git add .
|
||||||
|
git commit -m "$msg"
|
||||||
|
git push
|
@ -16,6 +16,6 @@
|
|||||||
"declaration": true,
|
"declaration": true,
|
||||||
"outDir": "dist"
|
"outDir": "dist"
|
||||||
},
|
},
|
||||||
"include": ["**/**.ts"],
|
"include": ["**/*.ts"],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @ts-check
|
|
||||||
|
|
||||||
export type TurboSyncConfigArray = TurboSyncConfigObject[];
|
export type TurboSyncConfigArray = TurboSyncConfigObject[];
|
||||||
|
|
||||||
export interface TurboSyncConfigObject {
|
export interface TurboSyncConfigObject {
|
||||||
|
Loading…
Reference in New Issue
Block a user