const fs = require('fs');

/**
 *
 * @param dir
 * @param extension
 * @returns {Array}
 */
exports.readDir = function (dir, extension = '*') {
    if (!fs.existsSync(dir)) {
        console.error('The src directory [ ' + dir + ' ] does not exist.');
        return;
    }

    const regex = new RegExp('\\.' + extension)
        ,files = fs.readdirSync(dir)
        ,_files = [];

    if (files) {
        files.forEach(function (file) {
            if (regex.test(file)) {
                _files.push(file);
            }
        });
    }
    return _files;
};



/**
 *
 * @param {String} dir
 * @param {String} file
 * @param {String} data
 */
function write (dir, file, data) {
    // Create a direcotry if doesn't exist.
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir);
    }

    const writeStream = fs.createWriteStream(dir.concat('/').concat(file), {
        autoClose: false
    });

    writeStream.write(data);
    writeStream.end(); // Close the write stream
}
exports.write = write;

@@ -200,10 +200,13 @@
 he s
+ou
 rc
+e
  dir
@@ -212,16 +212,24 @@
 rectory 
+or file 
 %5B ' + di
@@ -269,16 +269,19 @@
   return
+ %5B%5D
 ;%0A    %7D%0A

modify log message