Files
xMQL5/MQLTestWorkspace/BKPS/14030309/pack.js
T
2024-05-29 16:59:29 +03:30

86 lines
2.5 KiB
JavaScript

//
// Import Requirements ...
const execSync = require("child_process").execSync;
const XFileTools = require("./Documents/JsModules/x-file.tools");
const XShellTools = require("./Documents/JsModules/x-shell.tools");
const XColorTools = require("./Documents/JsModules/x-color.tools");
//
const packsPath = XFileTools.joinPath(".", "Packs");
handlePack();
async function handlePack() {
//
var date = new Date();
var folderName = date.toDateString()
.replace(" ", "");
//
const isPacksExists = XFileTools.isDirectoryExists(packsPath);
if (!isPacksExists) {
XFileTools.createDirectory(packsPath);
}
//
const isProjectExists = XFileTools.isDirectoryExists(folderName);
if (!isProjectExists) {
XFileTools.createDirectory(folderName);
}
//
const prjBasePath = XFileTools.joinPath(packsPath, folderName);
//
var foldersPath = [
"Classes",
"Experts",
"Helpers",
"Indicators",
"Libraries"
];
//
for (const path of foldersPath) {
//
const fSourcePath = XFileTools.joinPath(".", path);
const fDestPath = XFileTools.joinPath(prjBasePath, path);
XFileTools.createDirectory(fDestPath);
//
const filesToCopy = await XFileTools.extractFiles(fSourcePath, [".ex5", ".ex4"]);
if (!filesToCopy || filesToCopy.length == 0) {
return false;
}
//
// Loop through Files ...
for (const f of filesToCopy) {
//
// Prepare Destination Path ...
//
// Log ...
console.log(
XColorTools.applyForegroundColor("try to copy: ", XColorTools.COLOR_NAMES.Yellow),
XColorTools.applyForegroundColor(f, XColorTools.COLOR_NAMES.Blue),
XColorTools.applyForegroundColor(" to : ", XColorTools.COLOR_NAMES.Yellow),
XColorTools.applyForegroundColor(fDestPath, XColorTools.COLOR_NAMES.Magenta)
);
//
let result = await XFileTools.copyFile(f, fDestPath);
if (result) {
//
const msg = "copy successfully ...";
console.log(
XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green)
);
} else {
//
const msg = "copy failed ...";
console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red));
throw msg;
}
}
}
}