Compare commits
No commits in common. "219db3d88ee0c34fa36c14d162f72988d45fa2ff" and "ae4706c4c422de4492b01ca31f6494bb6539d5dd" have entirely different histories.
219db3d88e
...
ae4706c4c4
1
.gitignore
vendored
1
.gitignore
vendored
@ -177,4 +177,3 @@ out
|
|||||||
/test
|
/test
|
||||||
/lib-node
|
/lib-node
|
||||||
/dump
|
/dump
|
||||||
/bin
|
|
||||||
|
2
.npmrc
2
.npmrc
@ -1,2 +1,2 @@
|
|||||||
@moduletrace:registry=https://git.tben.me/api/packages/Moduletrace/npm/
|
@moduletrace:registry=https://git.tben.me/api/packages/moduletrace/npm/
|
||||||
//git.tben.me/api/packages/Moduletrace/npm/:_authToken=${GITBEN_NPM_TOKEN}
|
//git.tben.me/api/packages/Moduletrace/npm/:_authToken=${GITBEN_NPM_TOKEN}
|
||||||
|
BIN
bin/turbosync
Executable file
BIN
bin/turbosync
Executable file
Binary file not shown.
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
#! /usr/bin/env node
|
|
||||||
export {};
|
|
70
dist/index.js
vendored
70
dist/index.js
vendored
@ -1,70 +0,0 @@
|
|||||||
#! /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
1
dist/lib/sync.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export {};
|
|
46
dist/lib/sync.js
vendored
46
dist/lib/sync.js
vendored
@ -1,46 +0,0 @@
|
|||||||
"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
2
dist/lib/watch/files.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import { SyncFilesFnParams } from "../../types";
|
|
||||||
export default function watchFiles({ files, options, }: SyncFilesFnParams): Promise<void>;
|
|
152
dist/lib/watch/files.js
vendored
152
dist/lib/watch/files.js
vendored
@ -1,152 +0,0 @@
|
|||||||
"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
2
dist/lib/watch/folders.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import { SyncFoldersFnParams } from "../../types";
|
|
||||||
export default function watchFolders({ folders, options, }: SyncFoldersFnParams): Promise<void>;
|
|
154
dist/lib/watch/folders.js
vendored
154
dist/lib/watch/folders.js
vendored
@ -1,154 +0,0 @@
|
|||||||
"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
41
dist/types/index.d.ts
vendored
@ -1,41 +0,0 @@
|
|||||||
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
2
dist/types/index.js
vendored
@ -1,2 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
dist/utils/console-colors.d.ts
vendored
3
dist/utils/console-colors.d.ts
vendored
@ -1,3 +0,0 @@
|
|||||||
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 {};
|
|
1
dist/utils/delay.d.ts
vendored
1
dist/utils/delay.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export default function delay(time?: number): Promise<unknown>;
|
|
21
dist/utils/delay.js
vendored
21
dist/utils/delay.js
vendored
@ -1,21 +0,0 @@
|
|||||||
"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
2
dist/utils/env.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import { HandleEnvVarsFnParams } from "../types";
|
|
||||||
export default function handleEnvVars({ json }: HandleEnvVarsFnParams): string;
|
|
42
dist/utils/env.js
vendored
42
dist/utils/env.js
vendored
@ -1,42 +0,0 @@
|
|||||||
"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;
|
|
||||||
}
|
|
2
types/index.ts → index.d.ts
vendored
2
types/index.ts → index.d.ts
vendored
@ -1,3 +1,5 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
export type TurboSyncConfigArray = TurboSyncConfigObject[];
|
export type TurboSyncConfigArray = TurboSyncConfigObject[];
|
||||||
|
|
||||||
export interface TurboSyncConfigObject {
|
export interface TurboSyncConfigObject {
|
@ -1,9 +1,10 @@
|
|||||||
#! /usr/bin/env node
|
#! /usr/bin/env node
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
import fs from "fs";
|
const fs = require("fs");
|
||||||
import path from "path";
|
const path = require("path");
|
||||||
import { spawn } from "child_process";
|
const { spawn } = require("child_process");
|
||||||
import handleEnvVars from "./utils/env";
|
const handleEnvVars = require("./utils/env");
|
||||||
|
|
||||||
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
const confFileProvidedPath = process.argv[process.argv.length - 1];
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ try {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
console.log(`Process Error =>`, error.message);
|
console.log(`Process Error =>`, error.message);
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
@ -1,10 +1,15 @@
|
|||||||
import { spawn } from "child_process";
|
#! /usr/bin/env node
|
||||||
import watchFiles from "./watch/files";
|
|
||||||
import watchFolders from "./watch/folders";
|
// @ts-check
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
/** @type {import("..").TurboSyncConfigObject} */
|
||||||
const configFileObject = JSON.parse(confFileProvidedJSON);
|
const configFileObject = JSON.parse(confFileProvidedJSON);
|
||||||
|
|
||||||
console.log(`Running '${configFileObject.title}' ...`);
|
console.log(`Running '${configFileObject.title}' ...`);
|
@ -1,15 +1,19 @@
|
|||||||
import { execSync } from "child_process";
|
// @ts-check
|
||||||
import fs from "fs";
|
|
||||||
import delay from "../../utils/delay";
|
|
||||||
import { SyncFilesFnParams, SyncFilesSyncFnParams } from "../../types";
|
|
||||||
|
|
||||||
let timeout: any;
|
const { execSync } = require("child_process");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const delay = require("../../utils/delay");
|
||||||
|
|
||||||
|
/** @type {any} */
|
||||||
|
let timeout;
|
||||||
const UPDATE_TIMEOUT = 2000;
|
const UPDATE_TIMEOUT = 2000;
|
||||||
|
|
||||||
export default async function watchFiles({
|
/**
|
||||||
files,
|
*
|
||||||
options,
|
* @param {SyncFilesFnParams} param0
|
||||||
}: SyncFilesFnParams) {
|
*/
|
||||||
|
async function watchFiles({ files, options }) {
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i];
|
const file = files[i];
|
||||||
@ -49,7 +53,7 @@ export default async function watchFiles({
|
|||||||
options,
|
options,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`File Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`
|
`File Doesn't exist and couldn't be created. Please check if Directory exists.\nERROR => ${error.message}`
|
||||||
);
|
);
|
||||||
@ -86,13 +90,17 @@ export default async function watchFiles({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
console.log("ERROR:", error.message);
|
console.log("ERROR:", error.message);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sync({ options, filePath, files }: SyncFilesSyncFnParams) {
|
/**
|
||||||
|
*
|
||||||
|
* @param {SyncFilesSyncFnParams} param0
|
||||||
|
*/
|
||||||
|
function sync({ options, filePath, files }) {
|
||||||
const destFiles = files.filter((fl) => {
|
const destFiles = files.filter((fl) => {
|
||||||
if (typeof fl == "string") return fl !== filePath;
|
if (typeof fl == "string") return fl !== filePath;
|
||||||
if (fl?.path) return fl.path !== filePath;
|
if (fl?.path) return fl.path !== filePath;
|
||||||
@ -164,3 +172,5 @@ function sync({ options, filePath, files }: SyncFilesSyncFnParams) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = watchFiles;
|
@ -1,16 +1,19 @@
|
|||||||
import fs from "fs";
|
// @ts-check
|
||||||
import path from "path";
|
|
||||||
import { execSync } from "child_process";
|
|
||||||
import delay from "../../utils/delay";
|
|
||||||
import { SyncFoldersFnParams, SyncFoldersSyncFnParams } from "../../types";
|
|
||||||
|
|
||||||
let timeout: any;
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { execSync } = require("child_process");
|
||||||
|
const delay = require("../../utils/delay");
|
||||||
|
|
||||||
|
/** @type {any} */
|
||||||
|
let timeout;
|
||||||
const UPDATE_TIMEOUT = 2000;
|
const UPDATE_TIMEOUT = 2000;
|
||||||
|
|
||||||
export default async function watchFolders({
|
/**
|
||||||
folders,
|
*
|
||||||
options,
|
* @param {SyncFoldersFnParams} param0
|
||||||
}: SyncFoldersFnParams) {
|
*/
|
||||||
|
async function watchFolders({ folders, options }) {
|
||||||
try {
|
try {
|
||||||
const dirs = folders;
|
const dirs = folders;
|
||||||
|
|
||||||
@ -70,7 +73,7 @@ export default async function watchFolders({
|
|||||||
init: true,
|
init: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
console.log("Error:", error.message);
|
console.log("Error:", error.message);
|
||||||
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -94,13 +97,17 @@ export default async function watchFolders({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
console.log("ERROR:", error.message);
|
console.log("ERROR:", error.message);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) {
|
/**
|
||||||
|
*
|
||||||
|
* @param {SyncFoldersSyncFnParams} param0
|
||||||
|
*/
|
||||||
|
function sync({ options, dirs, dirPath, init }) {
|
||||||
const dstDirs = dirs.filter((dr) => {
|
const dstDirs = dirs.filter((dr) => {
|
||||||
if (typeof dr == "string") return dr !== dirPath;
|
if (typeof dr == "string") return dr !== dirPath;
|
||||||
if (dr?.path) return dr.path !== dirPath;
|
if (dr?.path) return dr.path !== dirPath;
|
||||||
@ -172,3 +179,5 @@ function sync({ options, dirs, dirPath, init }: SyncFoldersSyncFnParams) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = watchFolders;
|
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/turbosync",
|
"name": "@moduletrace/turbosync",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"module": "dist/index.js",
|
"module": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node dist/index.js",
|
"start": "node index.ts",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"compile": "bun build index.ts --compile --outfile bin/turbosync",
|
"compile": "bun build index.js --compile --outfile bin/turbosync",
|
||||||
"dev": "node index.js --watch"
|
"dev": "node index.js --watch"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"turbosync": "./dist/index.js"
|
"turbosync": "./index.js"
|
||||||
},
|
},
|
||||||
"description": "Sync files and directories with ease",
|
"description": "Sync files and directories with ease",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
tsc
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
msg="Updates"
|
msg="Updates"
|
||||||
else
|
else
|
||||||
@ -11,4 +9,4 @@ fi
|
|||||||
git add .
|
git add .
|
||||||
git commit -m "$msg"
|
git commit -m "$msg"
|
||||||
git push
|
git push
|
||||||
bun publish
|
npm publish
|
||||||
|
11
push.sh
11
push.sh
@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
msg="Updates"
|
|
||||||
else
|
|
||||||
msg="$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
git add .
|
|
||||||
git commit -m "$msg"
|
|
||||||
git push
|
|
@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "ES2015",
|
|
||||||
"module": "commonjs",
|
|
||||||
"maxNodeModuleJsDepth": 10,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"strict": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"lib": ["dom", "dom.iterable", "esnext"],
|
|
||||||
"allowJs": true,
|
|
||||||
"incremental": true,
|
|
||||||
"resolveJsonModule": true,
|
|
||||||
"jsx": "preserve",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"declaration": true,
|
|
||||||
"outDir": "dist"
|
|
||||||
},
|
|
||||||
"include": ["**/*.ts"],
|
|
||||||
"exclude": ["node_modules", "dist"]
|
|
||||||
}
|
|
130
dist/utils/console-colors.js → utils/console-colors.js
Normal file → Executable file
130
dist/utils/console-colors.js → utils/console-colors.js
Normal file → Executable file
@ -1,67 +1,63 @@
|
|||||||
"use strict";
|
// @ts-check
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.default = colors;
|
const colorCodes = {
|
||||||
const colorsArr = [
|
Reset: "\x1b[0m",
|
||||||
"red",
|
Bright: "\x1b[1m",
|
||||||
"bright",
|
Dim: "\x1b[2m",
|
||||||
"dim",
|
Underscore: "\x1b[4m",
|
||||||
"underscore",
|
Blink: "\x1b[5m",
|
||||||
"blink",
|
Reverse: "\x1b[7m",
|
||||||
"reverse",
|
Hidden: "\x1b[8m",
|
||||||
"hidden",
|
|
||||||
"black",
|
FgBlack: "\x1b[30m",
|
||||||
"green",
|
FgRed: "\x1b[31m",
|
||||||
"yellow",
|
FgGreen: "\x1b[32m",
|
||||||
"blue",
|
FgYellow: "\x1b[33m",
|
||||||
"magenta",
|
FgBlue: "\x1b[34m",
|
||||||
"cyan",
|
FgMagenta: "\x1b[35m",
|
||||||
"white",
|
FgCyan: "\x1b[36m",
|
||||||
"gray",
|
FgWhite: "\x1b[37m",
|
||||||
];
|
FgGray: "\x1b[90m",
|
||||||
const colorCodes = {
|
|
||||||
Reset: "\x1b[0m",
|
BgBlack: "\x1b[40m",
|
||||||
Bright: "\x1b[1m",
|
BgRed: "\x1b[41m",
|
||||||
Dim: "\x1b[2m",
|
BgGreen: "\x1b[42m",
|
||||||
Underscore: "\x1b[4m",
|
BgYellow: "\x1b[43m",
|
||||||
Blink: "\x1b[5m",
|
BgBlue: "\x1b[44m",
|
||||||
Reverse: "\x1b[7m",
|
BgMagenta: "\x1b[45m",
|
||||||
Hidden: "\x1b[8m",
|
BgCyan: "\x1b[46m",
|
||||||
FgBlack: "\x1b[30m",
|
BgWhite: "\x1b[47m",
|
||||||
FgRed: "\x1b[31m",
|
BgGray: "\x1b[100m",
|
||||||
FgGreen: "\x1b[32m",
|
};
|
||||||
FgYellow: "\x1b[33m",
|
|
||||||
FgBlue: "\x1b[34m",
|
/**
|
||||||
FgMagenta: "\x1b[35m",
|
* @param {string} text
|
||||||
FgCyan: "\x1b[36m",
|
* @param {"red" | "bright"| "dim"| "underscore" | "blink" | "reverse" | "hidden" | "black" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray"} [type]
|
||||||
FgWhite: "\x1b[37m",
|
* @param {boolean} [bg]
|
||||||
FgGray: "\x1b[90m",
|
* @returns {string}
|
||||||
BgBlack: "\x1b[40m",
|
*/
|
||||||
BgRed: "\x1b[41m",
|
function colors(text, type, bg) {
|
||||||
BgGreen: "\x1b[42m",
|
let finalText = ``;
|
||||||
BgYellow: "\x1b[43m",
|
|
||||||
BgBlue: "\x1b[44m",
|
switch (type) {
|
||||||
BgMagenta: "\x1b[45m",
|
case "red":
|
||||||
BgCyan: "\x1b[46m",
|
finalText += bg ? colorCodes.BgRed : colorCodes.FgRed;
|
||||||
BgWhite: "\x1b[47m",
|
break;
|
||||||
BgGray: "\x1b[100m",
|
case "green":
|
||||||
};
|
finalText += bg ? colorCodes.BgGreen : colorCodes.FgGrBgGreen;
|
||||||
function colors(text, type, bg) {
|
break;
|
||||||
let finalText = ``;
|
case "blue":
|
||||||
switch (type) {
|
finalText += bg ? colorCodes.BgBlue : colorCodes.FgGrBgBlue;
|
||||||
case "red":
|
break;
|
||||||
finalText += bg ? colorCodes.BgRed : colorCodes.FgRed;
|
|
||||||
break;
|
default:
|
||||||
case "green":
|
finalText += colorCodes.Bright;
|
||||||
finalText += bg ? colorCodes.BgGreen : colorCodes.FgGreen;
|
break;
|
||||||
break;
|
}
|
||||||
case "blue":
|
finalText += `${text}${colorCodes.Reset}`;
|
||||||
finalText += bg ? colorCodes.BgBlue : colorCodes.FgBlue;
|
console.log("finalText", finalText);
|
||||||
break;
|
|
||||||
default:
|
return finalText;
|
||||||
finalText += colorCodes.Bright;
|
}
|
||||||
break;
|
|
||||||
}
|
module.exports = colors;
|
||||||
finalText += `${text}${colorCodes.Reset}`;
|
|
||||||
console.log("finalText", finalText);
|
|
||||||
return finalText;
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
const colorsArr = [
|
|
||||||
"red",
|
|
||||||
"bright",
|
|
||||||
"dim",
|
|
||||||
"underscore",
|
|
||||||
"blink",
|
|
||||||
"reverse",
|
|
||||||
"hidden",
|
|
||||||
"black",
|
|
||||||
"green",
|
|
||||||
"yellow",
|
|
||||||
"blue",
|
|
||||||
"magenta",
|
|
||||||
"cyan",
|
|
||||||
"white",
|
|
||||||
"gray",
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
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",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function colors(
|
|
||||||
text: string,
|
|
||||||
type: (typeof colorsArr)[number],
|
|
||||||
bg: boolean
|
|
||||||
): string {
|
|
||||||
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;
|
|
||||||
}
|
|
16
utils/delay.js
Normal file
16
utils/delay.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// @ts-check
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} [time]
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async function delay(time = 500) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve(true);
|
||||||
|
}, time);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = delay;
|
@ -1,7 +0,0 @@
|
|||||||
export default async function delay(time: number = 500) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(true);
|
|
||||||
}, time);
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,9 +1,14 @@
|
|||||||
import { HandleEnvVarsFnParams } from "../types";
|
// @ts-check
|
||||||
|
|
||||||
import fs from "fs";
|
const fs = require("fs");
|
||||||
import path from "path";
|
const path = require("path");
|
||||||
|
|
||||||
export default function handleEnvVars({ json }: HandleEnvVarsFnParams): string {
|
/**
|
||||||
|
*
|
||||||
|
* @param {HandleEnvVarsFnParams} param0
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
function handleEnvVars({ json }) {
|
||||||
let newJson = json;
|
let newJson = json;
|
||||||
try {
|
try {
|
||||||
let envVars = { ...process.env };
|
let envVars = { ...process.env };
|
||||||
@ -26,9 +31,7 @@ export default function handleEnvVars({ json }: HandleEnvVarsFnParams): string {
|
|||||||
const key = keyPairArray.shift();
|
const key = keyPairArray.shift();
|
||||||
const value = keyPairArray.join("=");
|
const value = keyPairArray.join("=");
|
||||||
|
|
||||||
if (!key) return;
|
const newEnvObject = {};
|
||||||
|
|
||||||
const newEnvObject: { [k: string]: any } = {};
|
|
||||||
newEnvObject[key] = value;
|
newEnvObject[key] = value;
|
||||||
|
|
||||||
envVars = { ...envVars, ...newEnvObject };
|
envVars = { ...envVars, ...newEnvObject };
|
||||||
@ -38,10 +41,12 @@ export default function handleEnvVars({ json }: HandleEnvVarsFnParams): string {
|
|||||||
for (let key in envVars) {
|
for (let key in envVars) {
|
||||||
newJson = newJson.replaceAll(`$${key}`, String(envVars[key]));
|
newJson = newJson.replaceAll(`$${key}`, String(envVars[key]));
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error) {
|
||||||
console.log(`Error replacing Environment variables`, error.message);
|
console.log(`Error replacing Environment variables`, error.message);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newJson;
|
return newJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = handleEnvVars;
|
Loading…
Reference in New Issue
Block a user