<commit_before>'use strict';

const highlight = require('highlight.js');
const config = require('config');
const marked = require('marked');
const http = require('http');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const orderObject = require('./util').orderObject;

/**
 * Reads a json file, if there is a problem reading
 * the file it returns null.
 * @param  {String} filePath
 * @return {Object}
 */
function readJSONFile (filePath) {
    try {
        return JSON.parse(fs.readFileSync(filePath));
    } catch (e) {
        return null;
    }
}

/**
 * Wraps a require so that if there is a problem reading
 * the file it returns null.
 * @param {String} filePath
 * @return {Object}
 */
function wrappedRequire (filePath) {
    try {
        return require(filePath);
    } catch (e) {
        return null;
    }
}

/**
 * Returns the array of permissions to be shown on the OAuth section of the docs.
 * @return {Object[]}
 */
function getPermissions () {
    try {
        return require('@mcph/beam-common').permissions;
    } catch (err) {
        if (err.code === 'MODULE_NOT_FOUND') {
            return [];
        }
        throw err;
    }
}

/**
 * Generates locals required for templating.
 * `permissions` is used for the REST API docs, they are displayed in a table.
 * @return {Object}
 */
function getLocals () {
    const restDoc = readJSONFile(path.join(__dirname, '/tmp/raml-doc.json'));
    marked.setOptions({
        highlight (code) {
            return require('highlight.js').highlightAuto(code).value;
        },
    });
<commit_msg>chore(build): warn when common is missing (#182)<commit_after>'use strict';

const highlight = require('highlight.js');
const config = require('config');
const marked = require('marked');
const http = require('http');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const orderObject = require('./util').orderObject;

/**
 * Reads a json file, if there is a problem reading
 * the file it returns null.
 * @param  {String} filePath
 * @return {Object}
 */
function readJSONFile (filePath) {
    try {
        return JSON.parse(fs.readFileSync(filePath));
    } catch (e) {
        return null;
    }
}

/**
 * Wraps a require so that if there is a problem reading
 * the file it returns null.
 * @param {String} filePath
 * @return {Object}
 */
function wrappedRequire (filePath) {
    try {
        return require(filePath);
    } catch (e) {
        return null;
    }
}

/**
 * Returns the array of permissions to be shown on the OAuth section of the docs.
 * @return {Object[]}
 */
function getPermissions () {
    try {
        return require('@mcph/beam-common').permissions;
    } catch (err) {
        if (err.code === 'MODULE_NOT_FOUND') {
            // eslint-disable-next-line no-console
            console.warn('Cannot find common module. OAuth scope table will be omitted.');
            return [];
        }
        throw err;
    }
}

/**
 * Generates locals required for templating.
 * `permissions` is used for the REST API docs, they are displayed in a table.
 * @return {Object}
 */
function getLocals () {
    const restDoc = readJSONFile(path.join(__dirname, '/tmp/raml-doc.json'));
    marked.setOptions({
        highlight (code) {
            return require('highlight.js').highlightAuto(code).value;
        },
    });

{'fraction_non_alphanumeric': 0.1375036884036589, 'fraction_numerical': 0.0008852168781351431, 'mean_word_length': 2.847900113507378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1818611', 'n_tokens_mistral': 1010, 'n_tokens_neox': 991, 'n_words': 314}