{"size": 1640, "ext": "js", "max_stars_repo_path": "bin/sortdata.js", "max_stars_repo_name": "ethanlook/surfer", "max_stars_repo_stars_event_min_datetime": "2017-09-05T22:18:09.000Z", "max_stars_repo_stars_event_max_datetime": "2020-09-08T17:48:43.000Z", "max_issues_repo_path": "bin/sortdata.js", "max_issues_repo_name": "ethanlook/surfer", "max_issues_repo_issues_event_min_datetime": "2016-06-09T16:56:00.000Z", "max_issues_repo_issues_event_max_datetime": "2018-06-30T00:07:38.000Z", "max_forks_repo_path": "bin/sortdata.js", "max_forks_repo_name": "ethanlook/surfer", "max_forks_repo_forks_event_min_datetime": "2016-06-07T18:57:02.000Z", "max_forks_repo_forks_event_max_datetime": "2018-04-18T18:31:43.000Z"}
{"max_stars_count": 3, "max_issues_count": 14, "max_forks_count": 2, "avg_line_length": 23.4285714286, "max_line_length": 74, "alphanum_fraction": 0.6817073171}
#!/usr/bin/env node --harmony

/* eslint-disable no-console */

const sortDataByDate = require('../lib').sortDataByDate;

const program = require('commander');
const fs = require('fs');
const chalk = require('chalk');
const path = require('path');

function printOptions() {
  console.log(chalk.blue.bold('input: ') + program.input);
  console.log(chalk.blue.bold('output: ') + program.output);
  console.log(chalk.blue.bold('verbose: ') + program.verbose);
}

function makeOutfileStream(output) {
  let ofs;
  if (output) {
    ofs = fs.createWriteStream(output);
  } else {
    ofs = process.stdout;
  }
  return ofs;
}

function writeToOutfileStream(output, outfileStream, info) {
  if (output) {
    outfileStream.write(info);
  } else {
    console.log(info);
  }
}

program
  .version('1.0.0')
  .option('-i, --input <input>', 'path/to/input.json')
  .option('-o, --output <output>', 'path/to/output.json')
  .option('-v, --verbose', 'Verbose output.')
  .parse(process.argv);

if (program.verbose) {
  printOptions();
}

if (program.verbose) {
  console.log(chalk.yellow.bold('Reading in data...'));
}

// eslint-disable-next-line import/no-dynamic-require
const data = require(path.resolve(process.cwd(), program.input));

if (program.verbose) {
  console.log(chalk.yellow.bold('Sorting data...'));
}

sortDataByDate(data);

if (program.verbose) {
  console.log(chalk.yellow.bold('Writing data...'));
}

const outfileStream = makeOutfileStream(program.output);
writeToOutfileStream(program.output, outfileStream, JSON.stringify(data));

if (program.verbose) {
  console.log(chalk.yellow.bold('Done sorting and writing data...'));
}
