Files

145 lines
5.1 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 prjBasePath = XFileTools.joinPath(packsPath, folderName);
//
const prjBaseSourcePath = XFileTools.joinPath(prjBasePath, "Source");
const prjBaseCompiledPath = XFileTools.joinPath(prjBasePath, "Compile");
//
const isPacksExists = XFileTools.isDirectoryExists(packsPath);
if (!isPacksExists) {
XFileTools.createDirectory(packsPath);
}
//
const isProjectExists = XFileTools.isDirectoryExists(prjBasePath);
if (!isProjectExists) {
XFileTools.createDirectory(prjBasePath);
}
//
const isPrjBaseSourcePathExists = XFileTools.isDirectoryExists(prjBaseSourcePath);
if (!isPrjBaseSourcePathExists) {
XFileTools.createDirectory(prjBaseSourcePath);
}
//
const isPrjBaseCompiledPathExists = XFileTools.isDirectoryExists(prjBaseCompiledPath);
if (!isPrjBaseCompiledPathExists) {
XFileTools.createDirectory(prjBaseCompiledPath);
}
//
var foldersPath = [
"Classes", // Required Classes
"Experts", // Expert Advisers
"Helpers", // Indicator's Helpers Classes
"Indicators", // Required Indicators
"Libraries", // Required Libraries
"Parsers", // Strategies Filters based on Conditions
"Strategies", // Strategies Classes which Provides Signals
];
//
for (const path of foldersPath) {
//
const fSourcePath = XFileTools.joinPath(".", path);
//
// Copy Sources ...
const sourceFilesToCopy = await XFileTools.extractFiles(fSourcePath, [".mq5", ".mq4"]);
if (sourceFilesToCopy && sourceFilesToCopy.length > 0) {
//
const fDestPath = XFileTools.joinPath(prjBaseSourcePath, path);
XFileTools.createDirectory(fDestPath);
//
// Loop through Files ...
for (const f of sourceFilesToCopy) {
//
// 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;
}
}
}
//
// Copy Compiled ...
const compiledFilesToCopy = await XFileTools.extractFiles(fSourcePath, [".ex5", ".ex4"]);
if (compiledFilesToCopy && compiledFilesToCopy.length > 0) {
//
const fDestPath = XFileTools.joinPath(prjBaseCompiledPath, path);
XFileTools.createDirectory(fDestPath);
//
// Loop through Files ...
for (const f of compiledFilesToCopy) {
//
// 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;
}
}
}
}
}