<commit_before>const fs = require('fs');
const path = require('path');
const collectData = require('./collectData');
const { nun } = require('./nunjucks');

/**
 * Compiles template/data with Nunjucks into an HTML string
 * @param {String} template - The filename of the template to compile with
 * @param {Object} data
 * @returns {String} HTML String
 */
async function compile(template, data) {
  const compiledData = await collectData(data);

  return new Promise((resolve, reject) => {
    const templateWithFormat = template.endsWith('.njk') ? template : `${template}.njk`;
    const templatePath = path.join(global.FLINT.templatePath, templateWithFormat);

    fs.readFile(templatePath, 'utf-8', async (err) => {
      if (err) reject(err);

      let html = await nun.render(templatePath, compiledData);

      if (global.FLINT.debugMode) {
        const scr = `
        console.log('%cFlint Debug Mode', 'color: #fe6300; font-weight: bold; font-size: 1.2rem;');

        console.groupCollapsed('this');
          console.log(${JSON.stringify(compiledData.this)});
        console.groupEnd();

        console.groupCollapsed('Flint');
          console.table(${JSON.stringify(compiledData.flint.pages)});
          console.table(${JSON.stringify(compiledData.flint.entries)});
          console.table(${JSON.stringify(compiledData.flint.sections)});
          console.table(${JSON.stringify(compiledData.flint.fields)});
        console.groupEnd();
        `;

        html = await html.replace('</body>', `<script>${scr}</script></body>`);
      }

      resolve(html);
    });
  });
}

module.exports = compile;
<commit_msg>:wrench: Flint => flint in debugMode console logging<commit_after>const fs = require('fs');
const path = require('path');
const collectData = require('./collectData');
const { nun } = require('./nunjucks');

/**
 * Compiles template/data with Nunjucks into an HTML string
 * @param {String} template - The filename of the template to compile with
 * @param {Object} data
 * @returns {String} HTML String
 */
async function compile(template, data) {
  const compiledData = await collectData(data);

  return new Promise((resolve, reject) => {
    const templateWithFormat = template.endsWith('.njk') ? template : `${template}.njk`;
    const templatePath = path.join(global.FLINT.templatePath, templateWithFormat);

    fs.readFile(templatePath, 'utf-8', async (err) => {
      if (err) reject(err);

      let html = await nun.render(templatePath, compiledData);

      if (global.FLINT.debugMode) {
        const scr = `
        console.log('%cFlint Debug Mode', 'color: #fe6300; font-weight: bold; font-size: 1.2rem;');

        console.groupCollapsed('this');
          console.log(${JSON.stringify(compiledData.this)});
        console.groupEnd();

        console.groupCollapsed('flint');
          console.table(${JSON.stringify(compiledData.flint.pages)});
          console.table(${JSON.stringify(compiledData.flint.entries)});
          console.table(${JSON.stringify(compiledData.flint.sections)});
          console.table(${JSON.stringify(compiledData.flint.fields)});
        console.groupEnd();
        `;

        html = await html.replace('</body>', `<script>${scr}</script></body>`);
      }

      resolve(html);
    });
  });
}

module.exports = compile;

{'fraction_non_alphanumeric': 0.15905654671908073, 'fraction_numerical': 0.0042334442092530995, 'mean_word_length': 3.4702702702702704, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '3675712', 'n_tokens_mistral': 987, 'n_tokens_neox': 957, 'n_words': 206}