<commit_before>const fs = require("fs");
const path = require("path");
const promisify = require("es6-promisify");
const mkdirp = promisify(require("mkdirp"));
const writeFile = promisify(fs.writeFile);
const async = require("async");

module.exports = function build(acetate) {
  const _buildTimer = acetate.log.time();

  return acetate
    .getPages()
    .then(pages => pages.filter(p => !p.ignore))
    .then(function(pages) {
      return new Promise(function(resolve, reject) {
        const buildQueue = async.queue(function(page, callback) {
          return acetate.transformPage(page)
            .then(page => acetate.renderPage(page))
            .then(output => writeFile(outputPath, output))
            .then(callback)
            .catch(e => {
              buildQueue.kill();
              callback(e, null);
              reject(e);
            });
        }, 5);

        buildQueue.drain = function() {
          resolve(pages);
        };

        buildQueue.push(pages);
      });
    })
    .then(function(pages) {
      acetate.log.success(
        `Built ${pages.length} page in ${acetate.log.timeEnd(_buildTimer)}`
      );
    });
};
<commit_msg>builder - js - wrap mkdirp, writeFile in Promise.all after page render<commit_after>const fs = require("fs");
const path = require("path");
const promisify = require("es6-promisify");
const mkdirp = promisify(require("mkdirp"));
const writeFile = promisify(fs.writeFile);
const async = require("async");

module.exports = function build(acetate) {
  const _buildTimer = acetate.log.time();

  return acetate
    .getPages()
    .then(pages => pages.filter(p => !p.ignore))
    .then(function(pages) {
      return new Promise(function(resolve, reject) {
        const buildQueue = async.queue(function(page, callback) {
          return acetate.transformPage(page)
            .then(page => acetate.renderPage(page))
            .then(output => {
              return Promise.all([
                mkdirp(path.join(acetate.outDir, path.dirname(page.dest))),
              ]).then(() => {
                return writeFile(path.join(acetate.outDir, page.dest), output);
              });
            })
            .then(callback)
            .catch(e => {
              buildQueue.kill();
              callback(e, null);
              reject(e);
            });
        }, 5);

        buildQueue.drain = function() {
          resolve(pages);
        };

        buildQueue.push(pages);
      });
    })
    .then(function(pages) {
      acetate.log.success(
        `Built ${pages.length} page in ${acetate.log.timeEnd(_buildTimer)}`
      );
    });
};


{'fraction_non_alphanumeric': 0.14899277841125047, 'fraction_numerical': 0.0015203344735841885, 'mean_word_length': 2.229447852760736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '311821', 'n_tokens_mistral': 794, 'n_tokens_neox': 746, 'n_words': 144}