<commit_before>'use strict';

var fs = require('fs');
var hopsRoot = require('hops-root');
var hopsConfig = require('.');

var manifestData = null;
var manifestScript = '';

function getRawManifestData () {
  if (!manifestData) {
    manifestData = hopsRoot.require(
      hopsConfig.buildDir,
      'manifest.json'
    );
  }
  return Object.assign({}, manifestData);
}

exports.getManifestScript = function () {
  if (!manifestScript) {
    var filename = getRawManifestData()['manifest.js'];
    if (filename) {
      var filepath = hopsRoot.resolve(
        hopsConfig.buildDir,
        filename.replace(/^\/*/, '')
      );
      if (fs.existsSync(filepath)) {
        manifestScript = fs.readFileSync(filepath, 'utf8');
      }
    }
  }
  return manifestScript;
};

exports.getAssetLinks = function () {
  var vjs = 'vendor.js';
  var manifest = getRawManifestData();
  return Object.keys(manifest).sort(function (a, b) {
    return a === vjs ? -1 : b === vjs ? 1 : a < b ? -1 : a > b ? 1 : 0;
  }).reduce(function (assets, key) {
    if (!/^(chunk|manifest).*\.js/.test(key)) {
      if (/\.js$/.test(key)) {
        assets.js.push(manifest[key]);
      }
      if (/\.css$/.test(key)) {
        assets.css.push(manifest[key]);
      }
    }
    return assets;
  }, { js: [], css: [] });
};<commit_msg>make manifest utils more robust<commit_after>'use strict';

var fs = require('fs');
var hopsRoot = require('hops-root');
var hopsConfig = require('.');

var manifestData = null;
var manifestScript = '';

function getRawManifestData () {
  if (!manifestData) {
    var filepath = hopsRoot.resolve(
      hopsConfig.buildDir,
      'manifest.json'
    );
    if (fs.existsSync(filepath)) {
      manifestData = require(filepath);
    }
  }
  return manifestData || {};
}

exports.getManifestScript = function () {
  if (!manifestScript) {
    var filename = getRawManifestData()['manifest.js'];
    if (filename) {
      var filepath = hopsRoot.resolve(
        hopsConfig.buildDir,
        filename.replace(/^\/*/, '')
      );
      if (fs.existsSync(filepath)) {
        manifestScript = fs.readFileSync(filepath, 'utf8');
      }
    }
  }
  return manifestScript;
};

exports.getAssetLinks = function () {
  var vjs = 'vendor.js';
  var manifest = getRawManifestData() || {};
  return Object.keys(manifest).sort(function (a, b) {
    return a === vjs ? -1 : b === vjs ? 1 : a < b ? -1 : a > b ? 1 : 0;
  }).reduce(function (assets, key) {
    if (!/^(chunk|manifest).*\.js/.test(key)) {
      if (/\.js$/.test(key)) {
        assets.js.push(manifest[key]);
      }
      if (/\.css$/.test(key)) {
        assets.css.push(manifest[key]);
      }
    }
    return assets;
  }, { js: [], css: [] });
};
{'fraction_non_alphanumeric': 0.18178466076696165, 'fraction_numerical': 0.004424778761061947, 'mean_word_length': 2.676151761517615, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1744183', 'n_tokens_mistral': 926, 'n_tokens_neox': 898, 'n_words': 186}