modules/shared/file_helper.mjs

export { find_all_json_files };

/**
 * returns an array of JSON files in and below root directory path
 * @param {string} root path to start recursive seach for files
 * @param {string[]} [file_list=[]] the list of files found so far (iterative call)
 * @returns {string[]}
 */
function find_all_json_files(root, file_list = []) {
    if (Unix()) var slash = "/";
    else var slash = "\\";

    //let file_list = [];

    for (let file_OR_dir of File.FindFiles(root, File.DIRECTORY | File.FILE)) {
        let path = `${root}${slash}${file_OR_dir}`;
        if (File.IsFile(path)) {
            //Message(path);
            if (/\.json$/i.test(file_OR_dir)) file_list.push(path);
        } else if (File.IsDirectory(path)) file_list.concat(find_all_json_files(path, file_list));
    }

    return file_list;
}