prepare pack.js for packing robot ...
This commit is contained in:
@@ -366,7 +366,7 @@ async function getRecursiveFilesList(
|
|||||||
|
|
||||||
//
|
//
|
||||||
const contents = await getDirectoryContents(path);
|
const contents = await getDirectoryContents(path);
|
||||||
for(const item of contents) {
|
for (const item of contents) {
|
||||||
//
|
//
|
||||||
const itemPath = joinPath(
|
const itemPath = joinPath(
|
||||||
path,
|
path,
|
||||||
@@ -396,6 +396,65 @@ async function getRecursiveFilesList(
|
|||||||
//
|
//
|
||||||
return result;
|
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
|
//#endregion
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -814,6 +873,7 @@ module.exports = {
|
|||||||
getFileExtension,
|
getFileExtension,
|
||||||
removeFileExtension,
|
removeFileExtension,
|
||||||
getRecursiveFilesList,
|
getRecursiveFilesList,
|
||||||
|
extractFiles,
|
||||||
|
|
||||||
//
|
//
|
||||||
copyFolder,
|
copyFolder,
|
||||||
@@ -826,5 +886,5 @@ module.exports = {
|
|||||||
getDirectoryFiles,
|
getDirectoryFiles,
|
||||||
getDirectoryFolders,
|
getDirectoryFolders,
|
||||||
getDirectoryContents,
|
getDirectoryContents,
|
||||||
}
|
};
|
||||||
//#endregion
|
//#endregion
|
||||||
@@ -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
@@ -9,6 +9,7 @@
|
|||||||
"aab": "| Commons |",
|
"aab": "| Commons |",
|
||||||
"aac": "|----------|",
|
"aac": "|----------|",
|
||||||
"compile": "node compile.js",
|
"compile": "node compile.js",
|
||||||
|
"pack": "node pack.js",
|
||||||
"compileWorkspace": "npm run compile",
|
"compileWorkspace": "npm run compile",
|
||||||
"compileExperts": "npm run compile **experts",
|
"compileExperts": "npm run compile **experts",
|
||||||
"compileLibraries": "npm run compile **libraries",
|
"compileLibraries": "npm run compile **libraries",
|
||||||
@@ -27,7 +28,8 @@
|
|||||||
"rmClassesEx": "shx --silent rm -r ./Classes/*.ex5 || npm run true",
|
"rmClassesEx": "shx --silent rm -r ./Classes/*.ex5 || npm run true",
|
||||||
"rmIndicatorsEx": "shx --silent rm -r ./Indicators/*.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",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user