<commit_before>#!/usr/bin/env node

if (process.argv.includes('--help') || process.argv.includes('-h')) {
    console.info(`Usage: ${__filename.slice(__dirname.length + 1)} [-h|--help] [--dry]`);
    process.exit(0);
}

const isDry = process.argv.includes('--dry');

const fs = require('fs');
const config = require('../config/environment')(process.env.EMBER_ENV);

const {providers} = config.PREPRINTS;
const hostsFileName = '/etc/hosts';
const hostIP = '127.0.0.1';
const hostsFile = fs.readFileSync(hostsFileName, {encoding: 'utf8'});
const sectionHeader = '## EMBER-PREPRINTS ##\n';
const sectionFooter = '\n## /EMBER-PREPRINTS ##';
const rgx = new RegExp(`(?:${sectionHeader})(.|\\s)*(?:${sectionFooter})`, 'm');
const domainProviders = providers.filter(provider => provider.domain);

const maxLength = domainProviders
    .map(provider => provider.domain)
    .reduce((a, b) => a.length > b.length ? a.length : b.length);

const lines = domainProviders
    .map(provider => `${hostIP}\tlocal.${provider.domain}${' '.repeat(maxLength - provider.domain.length)}\t# ${provider.id}`)
    .join('\n');

const section = `${sectionHeader}${lines}${sectionFooter}`;
const resultFile = rgx.test(hostsFile) ? hostsFile.replace(rgx, section) : `${hostsFile}\n\n${section}`;

console.info(`Resulting file:\n${resultFile}`);

if (isDry) {
    console.log('!!! DRY RUN, File not written !!!');
    process.exit(0);
}

fs.writeFileSync(hostsFileName, resultFile, {encoding: 'utf8'});
<commit_msg>Update add domains script<commit_after>#!/usr/bin/env node

if (process.argv.includes('--help') || process.argv.includes('-h')) {
    console.info(`Usage: ${__filename.slice(__dirname.length + 1)} [-h|--help] [--dry]`);
    process.exit(0);
}

const isDry = process.argv.includes('--dry');

const fs = require('fs');
const config = require('../config/environment')(process.env.EMBER_ENV);

const {providers} = config.PREPRINTS;
const hostsFileName = '/etc/hosts';
const hostIP = '127.0.0.1';
const hostsFile = fs.readFileSync(hostsFileName, {encoding: 'utf8'});
const sectionHeader = '## EMBER-PREPRINTS ##\n';
const sectionFooter = '\n## /EMBER-PREPRINTS ##';
const rgx = new RegExp(`(?:${sectionHeader})(.|\\s)*(?:${sectionFooter})`, 'm');
const domainProviders = providers
    .slice(1)
    .filter(provider => provider.domain)
    .map(provider => {
        provider.domain = provider.domain.replace(/:.*$/, '');
        return provider;
    });

const maxLength = domainProviders
    .map(provider => provider.domain)
    .reduce((a, b) => a.length > b.length ? a.length : b.length);

const lines = domainProviders
    .map(provider => `${hostIP}\t${provider.domain}${' '.repeat(maxLength - provider.domain.length)}\t# ${provider.id}`)
    .join('\n');

const section = `${sectionHeader}${lines}${sectionFooter}`;
const resultFile = rgx.test(hostsFile) ? hostsFile.replace(rgx, section) : `${hostsFile}\n\n${section}`;

console.info(`Resulting file:\n${resultFile}`);

if (isDry) {
    console.log('!!! DRY RUN, File not written !!!');
    process.exit(0);
}

fs.writeFileSync(hostsFileName, resultFile, {encoding: 'utf8'});

{'fraction_non_alphanumeric': 0.21174205967276227, 'fraction_numerical': 0.007378889958293231, 'mean_word_length': 4.721100917431193, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1965603', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1062, 'n_words': 200}