<commit_before>"use strict";

const config = require("config");
const moment = require('moment');
const fs = require('fs');
const fse = require('fs-extra');

const log = require("./helpers/logger");

let format = process.env.FORMAT || (config.has('app.format') ? config.get('app.format').toLowerCase() : "json");
let writeConfig = process.env.FORMAT|| (config.has('app.write_to_file') ? config.get('app.write_to_file') : "false");
const supportedFormats = ["json", "csv"];
const ts = moment().format("YYYY-MM-DD-HH.mm.ss");
const dir = "./output/" + process.env.NODE_ENV + "-" + ts;



if(process.env.NODE_ENV.indexOf("tableau") > -1 && writeConfig === true){
    if (!fs.existsSync(dir)){
        fs.mkdirSync(dir);
    }
    let destFile = dir + '/' + process.env.NODE_ENV + '.twb';

    fse.copy('./lib/tableau/standard-tableau.twb', destFile, function (err) {
        if (err) {
            log.error("Unable to copy Tableau source file.");
        }
        fs.readFile(destFile, 'utf8', function (readErr, data) {
            if (readErr) {
                log.error("Unable to read Tableau source file");
            } else {
                //replace workbook name
                let result = data.replace(/standard-tableau/g, process.env.NODE_ENV);
                let out = result.replace(/ directory=''/g, " directory='.//'");
                fs.writeFile(destFile, out, 'utf8', function (writeErr) {
                    if (writeErr) {
                        log.error("Unable to write to Tableau destFile file.");
                    }
                });
            }
        });
    });
}

/**
 * write - files to disk
 * @param fileName - string
 * @param content - string
 * @returns {promise}
 */
const write = function write(fileName, content) {
    return new Promise(function(resolve, reject){

        if(supportedFormats.indexOf(format) === -1){
            log.warn("Invalid config: app.format. Defaulting to json");
            format = "json";
        }

        if(writeConfig === "false"){<commit_msg>Fix to disable file writer.<commit_after>"use strict";

const config = require("config");
const moment = require('moment');
const fs = require('fs');
const fse = require('fs-extra');

const log = require("./helpers/logger");

let format = process.env.FORMAT || (config.has('app.format') ? config.get('app.format').toLowerCase() : "json");
let writeConfig = process.env.FORMAT|| (config.has('app.write_to_file') ? config.get('app.write_to_file') : "false");
const supportedFormats = ["json", "csv"];
const ts = moment().format("YYYY-MM-DD-HH.mm.ss");
const dir = "./output/" + process.env.NODE_ENV + "-" + ts;



if(process.env.NODE_ENV.indexOf("tableau") > -1 && writeConfig === true){
    if (!fs.existsSync(dir)){
        fs.mkdirSync(dir);
    }
    let destFile = dir + '/' + process.env.NODE_ENV + '.twb';

    fse.copy('./lib/tableau/standard-tableau.twb', destFile, function (err) {
        if (err) {
            log.error("Unable to copy Tableau source file.");
        }
        fs.readFile(destFile, 'utf8', function (readErr, data) {
            if (readErr) {
                log.error("Unable to read Tableau source file");
            } else {
                //replace workbook name
                let result = data.replace(/standard-tableau/g, process.env.NODE_ENV);
                let out = result.replace(/ directory=''/g, " directory='.//'");
                fs.writeFile(destFile, out, 'utf8', function (writeErr) {
                    if (writeErr) {
                        log.error("Unable to write to Tableau destFile file.");
                    }
                });
            }
        });
    });
}

/**
 * write - files to disk
 * @param fileName - string
 * @param content - string
 * @returns {promise}
 */
const write = function write(fileName, content) {
    return new Promise(function(resolve, reject){

        if(supportedFormats.indexOf(format) === -1){
            log.warn("Invalid config: app.format. Defaulting to json");
            format = "json";
        }

        if(writeConfig === false){
{'fraction_non_alphanumeric': 0.16707556427870462, 'fraction_numerical': 0.001962708537782139, 'mean_word_length': 2.3254486133768353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '166841', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1191, 'n_words': 279}