146 lines
4.7 KiB
JavaScript
146 lines
4.7 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 year = date.getFullYear();
|
|
var month = date.getMonth() + 1;
|
|
var day = date.getDate();
|
|
var hour = date.getHours();
|
|
var min = date.getMinutes();
|
|
|
|
//
|
|
var folderName = year.toString() + "-" + month.toString() + "-" + day.toString() + "(" + hour.toString() + "_" + min.toString() + ")";
|
|
|
|
//
|
|
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);
|
|
|
|
//
|
|
// Source Copy ...
|
|
let fDestPath = XFileTools.joinPath(prjBaseSourcePath, path);
|
|
|
|
//
|
|
// Log ...
|
|
console.log(
|
|
XColorTools.applyForegroundColor("try to copy: ", XColorTools.COLOR_NAMES.Yellow),
|
|
XColorTools.applyForegroundColor(path, XColorTools.COLOR_NAMES.Blue),
|
|
XColorTools.applyForegroundColor(" to : ", XColorTools.COLOR_NAMES.Yellow),
|
|
XColorTools.applyForegroundColor(prjBaseSourcePath, XColorTools.COLOR_NAMES.Magenta)
|
|
);
|
|
|
|
//
|
|
// Copy Folder ...
|
|
let result = await XFileTools.copyFolder(fSourcePath, prjBaseSourcePath);
|
|
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;
|
|
}
|
|
|
|
//
|
|
// Cleanup Folder ...
|
|
const sourceFilesToRemove = await XFileTools.extractFiles(fDestPath, [".ex5", ".ex4"]);
|
|
for (const f of sourceFilesToRemove) {
|
|
await XFileTools.removeFile(f);
|
|
}
|
|
|
|
//
|
|
// Compile Copy ...
|
|
fDestPath = XFileTools.joinPath(prjBaseCompiledPath, path);
|
|
|
|
//
|
|
// Log ...
|
|
console.log(
|
|
XColorTools.applyForegroundColor("try to copy: ", XColorTools.COLOR_NAMES.Yellow),
|
|
XColorTools.applyForegroundColor(path, XColorTools.COLOR_NAMES.Blue),
|
|
XColorTools.applyForegroundColor(" to : ", XColorTools.COLOR_NAMES.Yellow),
|
|
XColorTools.applyForegroundColor(prjBaseCompiledPath, XColorTools.COLOR_NAMES.Magenta)
|
|
);
|
|
|
|
//
|
|
// Copy Folder ...
|
|
result = await XFileTools.copyFolder(fSourcePath, prjBaseCompiledPath);
|
|
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;
|
|
}
|
|
|
|
//
|
|
// Cleanup Folder ...
|
|
const compileFilesToRemove = await XFileTools.extractFiles(fDestPath, [".mq5", ".mq4"]);
|
|
for (const f of compileFilesToRemove) {
|
|
await XFileTools.removeFile(f);
|
|
}
|
|
}
|
|
} |