From 669f0b8377a3e6c7b952c6ed11f10ecada015b04 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 9 Jul 2024 13:23:32 +0330 Subject: [PATCH] add support for packing source and compile in separate folders when packing script run ... --- pack.js | 113 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/pack.js b/pack.js index 05f952b4..403f50d5 100644 --- a/pack.js +++ b/pack.js @@ -15,6 +15,13 @@ async function handlePack() { 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) { @@ -22,13 +29,22 @@ async function handlePack() { } // - const isProjectExists = XFileTools.isDirectoryExists(folderName); + const isProjectExists = XFileTools.isDirectoryExists(prjBasePath); if (!isProjectExists) { - XFileTools.createDirectory(folderName); + XFileTools.createDirectory(prjBasePath); } // - const prjBasePath = XFileTools.joinPath(packsPath, folderName); + const isPrjBaseSourcePathExists = XFileTools.isDirectoryExists(prjBaseSourcePath); + if (!isPrjBaseSourcePathExists) { + XFileTools.createDirectory(prjBaseSourcePath); + } + + // + const isPrjBaseCompiledPathExists = XFileTools.isDirectoryExists(prjBaseCompiledPath); + if (!isPrjBaseCompiledPathExists) { + XFileTools.createDirectory(prjBaseCompiledPath); + } // var foldersPath = [ @@ -43,43 +59,84 @@ async function handlePack() { 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; + // 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; + } + } } // - // Loop through Files ... - for (const f of filesToCopy) { + // Copy Compiled ... + const compiledFilesToCopy = await XFileTools.extractFiles(fSourcePath, [".ex5", ".ex4"]); + if (compiledFilesToCopy && compiledFilesToCopy.length > 0) { // - // Prepare Destination Path ... + const fDestPath = XFileTools.joinPath(prjBaseCompiledPath, path); + XFileTools.createDirectory(fDestPath); // - // 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) { + // Loop through Files ... + for (const f of compiledFilesToCopy) { // - const msg = "copy successfully ..."; + // Prepare Destination Path ... + + // + // Log ... console.log( - XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Green) + 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) ); - } else { + // - const msg = "copy failed ..."; - console.log(XColorTools.applyForegroundColor(msg, XColorTools.COLOR_NAMES.Red)); - throw msg; + 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; + } } } }