/* eslint-disable no-undef, no-unused-vars */

const fs = require('fs');
const path = require('path');

const config = require('../config')();

const rootFolder = process.cwd();
const componentPath = path.join(config.appFolder, config.componentsFolder);

const getData = (componentName, components) => {
    let currentProp = componentName;
    let subProp;
    if(componentName.split('.').length) {
        currentProp = componentName.split('.')[0];
        subProp = componentName.split('.')[1];
    }
    
    let jsonString = JSON.stringify(components[currentProp])
    
    let data = jsonString.replace(/"###(.*?)###"/g, (org, catched) => {
        let subData = this.getData(catched);
        return JSON.stringify(subData);
    })
    
    let parsedData = JSON.parse(data);
    return subProp ? parsedData[subProp] : parsedData;
}

const getFilesByExtension = (startPath, filter, allFiles = {}) =>{
    if (!fs.existsSync(startPath)){
        return;
    }

    let files = fs.readdirSync(startPath);
    for(let i=0; i < files.length; i++){
        let filename=path.join(startPath, files[i]);
        let stat = fs.lstatSync(filename);
        if (stat.isDirectory()){
            getFilesByExtension(filename, filter, allFiles);
        }
        else if (filename.endsWith(filter)) {
            let normalizedFile = path.posix.normalize(filename);
            let name = normalizedFile.split(path.sep).pop().split('.')[0];
            
            if(filter === '.json') {
                allFiles[name] = require(normalizedFile);
            } else {
                allFiles[name] = normalizedFile;
            }
            
        }
    }

    return allFiles;
}

const purgeCache = (moduleName) => {
    Object.keys(require.cache).forEach(function(key) {
        
        delete require.cache[key];
        
    });
}

class Log {
    static info(message) {
        console.info(message);
    }
    static error(message) {
        console.error(message);
    }
}

module.exports = {
    getData,
    purgeCache,
    getFilesByExtension,
    Log
}

@@ -254,24 +254,514 @@
 Folder);%0D%0A%0D%0A
+const getAllJsonFiles = () =%3E %7B%0D%0A    const componentsFolder = path.join(%0D%0A        process.cwd(), %0D%0A        config.appFolder, %0D%0A        config.componentsFolder%0D%0A    )%0D%0A    const containersFolder = path.join(%0D%0A        process.cwd(), %0D%0A        config.appFolder, %0D%0A        config.containersFolder%0D%0A    )%0D%0A    %0D%0A    const jsonFiles = %7B%0D%0A        ...getFilesByExtension(componentsFolder, '.json'), %0D%0A        ...getFilesByExtension(containersFolder, '.json')%0D%0A    %7D;%0D%0A%0D%0A    return jsonFiles;%0D%0A%7D%0D%0A%0D%0A
 const getDat
@@ -790,24 +790,31 @@
 mponents
+ = null
 ) =%3E %7B%0D%0A
     let 
@@ -801,24 +801,81 @@
 null) =%3E %7B%0D%0A
+    components = components %7C%7C getAllJsonFiles();%0D%0A    %0D%0A
     let curr
@@ -1211,24 +1211,24 @@
 ched) =%3E %7B%0D%0A
+
         let 
@@ -1241,13 +1241,8 @@
 a = 
-this.
 getD

Fix getData with subdata in json