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

import fs from 'fs-extra';
import path from 'path';
import glob from 'glob';
import colors from 'cli-color';
import Debug from 'debug';
import { Merger } from '../lib/merger';
import { done } from '../utils/done';
import program from 'commander';

const debug = Debug('sol-merger:debug');

let inputGlob: string, outputDir: string, append: string;

program
  .option('-a, --append [append]', '', /^([a-zA-Z_]+)$/)
  .option('-c, --remove-comments', `Remove comment from exports`, false)
  .arguments('<glob> [outputDir]')
  .action((_glob, _outputDir) => {
    inputGlob = _glob;
    outputDir = _outputDir;
  })
  .parse(process.argv);

if (!inputGlob) {
  console.log(colors.red('Please specify input solidity contract.'));
  program.outputHelp();
  done();
}

append = program.append || '_merged';

if (outputDir) {
  outputDir = path.isAbsolute(outputDir)
    ? outputDir
    : path.join(process.cwd(), outputDir);
}

debug('Output directory', outputDir);
debug('RemoveComments?', program.removeComments);

glob(
  inputGlob,
  {
    cwd: process.cwd(),
    absolute: true,
  },
  execute
);

async function execute(err: Error, files: string[]) {
  if (err) {
    return done(err);
  }

  debug(files);

  if (files.length === 0) {
    // eslint-disable-next-line
    console.log(colors.yellow('No files found for merge'));
  }

  const promises = files.map(async (file) => {
    const merger = new Merger({ delimeter: '\n\n', removeComments: program.removeComments });
    let result: string;
    result = await merger.processFile(file, true);
    let outputFile: string;
    if (outputDir) {
      outputFile = path.join(outputDir, path.basename(file));
    } else {
      const extname = path.extname(file);
      outputFile = path.join(
        path.dirname(file),
        path.basename(file, extname) + append + extname
      );
    }
    debug(`${file} -> ${outputFile}`);
    await fs.outputFile(outputFile, result, { encoding: 'utf-8' });
  });

  Promise.all(promises)
    .then(() => done())
    .catch(done);
}<commit_msg>refactor(bin): assign variables to empty strings<commit_after>#!/usr/bin/env node

import fs from 'fs-extra';
import path from 'path';
import glob from 'glob';
import colors from 'cli-color';
import Debug from 'debug';
import { Merger } from '../lib/merger';
import { done } from '../utils/done';
import program from 'commander';

const debug = Debug('sol-merger:debug');

let inputGlob = '';
let outputDir = '';
let append = '';

program
  .option('-a, --append [append]', '', /^([a-zA-Z_]+)$/)
  .option('-c, --remove-comments', `Remove comment from exports`, false)
  .arguments('<glob> [outputDir]')
  .action((_glob, _outputDir) => {
    inputGlob = _glob;
    outputDir = _outputDir;
  })
  .parse(process.argv);

if (!inputGlob) {
  console.log(colors.red('Please specify input solidity contract.'));
  program.outputHelp();
  done();
}

append = program.append || '_merged';

if (outputDir) {
  outputDir = path.isAbsolute(outputDir)
    ? outputDir
    : path.join(process.cwd(), outputDir);
}

debug('Output directory', outputDir);
debug('RemoveComments?', program.removeComments);

glob(
  inputGlob,
  {
    cwd: process.cwd(),
    absolute: true,
  },
  execute,
);

async function execute(err: Error, files: string[]) {
  if (err) {
    return done(err);
  }

  debug(files);

  if (files.length === 0) {
    // eslint-disable-next-line
    console.log(colors.yellow('No files found for merge'));
  }

  const promises = files.map(async (file) => {
    const merger = new Merger({
      delimeter: '\n\n',
      removeComments: program.removeComments,
    });
    let result: string;
    result = await merger.processFile(file, true);
    let outputFile: string;
    if (outputDir) {
      outputFile = path.join(outputDir, path.basename(file));
    } else {
      const extname = path.extname(file);
      outputFile = path.join(
        path.dirname(file),
        path.basename(file, extname) + append + extname,
      );
    }
    debug(`${file} -> ${outputFile}`);
    await fs.outputFile(outputFile, result, { encoding: 'utf-8' });
  });

  Promise.all(promises)
    .then(() => done())
    .catch(done);
}
{'fraction_non_alphanumeric': 0.17194570135746606, 'fraction_numerical': 0.0009526077637532746, 'mean_word_length': 3.4350580781414997, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1499616', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1376, 'n_words': 334}