prepare pack.js for packing robot ...

This commit is contained in:
2024-05-29 02:01:46 +03:30
parent 7904f7e56b
commit 4f95fe5ce7
3 changed files with 159 additions and 11 deletions
+70 -10
View File
@@ -349,7 +349,7 @@ function getFileExtension(path = '') {
* @returns {Promise<string[]>}
*/
async function getRecursiveFilesList(
path = "",
path = "",
extensions = []
) {
//
@@ -366,7 +366,7 @@ async function getRecursiveFilesList(
//
const contents = await getDirectoryContents(path);
for(const item of contents) {
for (const item of contents) {
//
const itemPath = joinPath(
path,
@@ -378,11 +378,11 @@ async function getRecursiveFilesList(
if (isItemFile) {
//
const itemFileExtension = getFileExtension(itemPath);
const isFileInSupportedExtensions =
extensions === undefined || extensions.length === 0
? true
: extensions.includes(itemFileExtension)
;
const isFileInSupportedExtensions =
extensions === undefined || extensions.length === 0
? true
: extensions.includes(itemFileExtension)
;
if (isFileInSupportedExtensions) {
result.push(itemPath);
}
@@ -396,6 +396,65 @@ async function getRecursiveFilesList(
//
return result;
}
/**
* Extract Specific files from a folder and it's content ...
*
* @param {string} path Folder Path ...
* @returns
*/
async function extractFiles(path = "", ext = []) {
//
const result = [];
//
if (!ext || ext.length == 0) {
return result;
}
//
const pathContent = await getDirectoryContents(path);
if (!pathContent || pathContent.length == 0) {
return result;
}
//
// Loop through Content ...
for (const c of pathContent) {
//
// Prepare full path ...
const cPath = joinPath(path, c);
//
// check content path is file or not ...
const isCFile = isFileExists(cPath);
const isCDirectory = isDirectoryExists(cPath);
if (isCFile) {
//
// Check it is MQL file or not ...
const cExt = getFileExtension(cPath);
if (ext.includes(cExt)) {
result.push(cPath);
}
} else if (isCDirectory) {
//
const destFolderName = basename(cPath);
const isExcluded = excludeWorkspaceFolders.includes(destFolderName);
if (isExcluded) {
continue;
}
//
const cFiles = await extractFiles(cPath, ext);
if (cFiles && cFiles.length > 0) {
result.push(...cFiles);
}
}
}
//
return result;
}
//#endregion
//
@@ -770,8 +829,8 @@ async function writeJSON(
//
result = await writeFile(
path,
contentString,
path,
contentString,
true
);
@@ -814,6 +873,7 @@ module.exports = {
getFileExtension,
removeFileExtension,
getRecursiveFilesList,
extractFiles,
//
copyFolder,
@@ -826,5 +886,5 @@ module.exports = {
getDirectoryFiles,
getDirectoryFolders,
getDirectoryContents,
}
};
//#endregion
+86
View File
@@ -0,0 +1,86 @@
//
// 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;
}
}
}
}
+3 -1
View File
@@ -9,6 +9,7 @@
"aab": "| Commons |",
"aac": "|----------|",
"compile": "node compile.js",
"pack": "node pack.js",
"compileWorkspace": "npm run compile",
"compileExperts": "npm run compile **experts",
"compileLibraries": "npm run compile **libraries",
@@ -27,7 +28,8 @@
"rmClassesEx": "shx --silent rm -r ./Classes/*.ex5 || npm run true",
"rmIndicatorsEx": "shx --silent rm -r ./Indicators/*.ex5 || npm run true",
"cleanupEx": "npm run rmExpertsEx && npm run rmLibrariesEx && npm run rmHelpersEx && npm run rmClassesEx && npm run rmIndicatorsEx",
"prepareWorkspace": "npm run cleanupEx && npm run compileProject"
"prepareWorkspace": "npm run cleanupEx && npm run compileProject",
"generatePack": "npm run prepareWorkspace && npm run pack"
},
"repository": {
"type": "git",