<commit_before>#!/usr/bin/env node
"use strict";
const fs = require('fs'),
  open = require('open'),
  trumpet = require('trumpet'),
  program = require('commander'),
  temp = require('temp'),
  jsStringEscape = require('js-string-escape'),
  columnsPageStream = require('json-columns-template'),
  currentVersion = require('./package.json').version;
 
// Process the data (note: error handling omitted) 
var myTemp = temp.open({suffix: '.html'});

//use the Commander package to parse user-supplied parameters and auto-generate a --help document
let inputPath;
program
  .version(currentVersion)
  .arguments('<path to JSON file>')
  .action(function (path) {
    inputPath = path;
  })
  .parse(process.argv);

fs.readFile(inputPath, processData);

//will receive readable stream from fs.readFile
function processData(err, data) {
  if (err) {
    console.error(err);
  } else {
    const fileContents = data.toString();
    const escapedString = jsStringEscape(fileContents);
    
    checkForValidJson(fileContents);
    createPageWithData(escapedString, true);
  }
}

//abort the process and display an error msg if the provided user data isn't valid JSON
function checkForValidJson(string) {
  try {
    JSON.parse(string);
    return true;
  } catch (err) {
    if (err instanceof SyntaxError) {
      console.log('Error: not a valid JSON string. ', err.message);
    } else {
      console.log('Unexpected error.');
      console.error(err);
    }
    process.exit();
  }
}

function createPageWithData(userData, openPage) {
  const assetPath = __dirname + '/node_modules/json-columns-template/build';
  // const tempFile = __dirname + '/temp/temp.html';
  const tempFile = temp.path({suffix: '.html'});
  const tr = trumpet();
  
  //add code defining a variable to a blank script in source HTML file.
  tr.select('#preload-data')
    .createWriteStream()
    .end(`var preloadedUserData = '${userData}'`);

  //direct generated page to local versions of assets
  tr.select('#bundle')
    .setAttribute('src', assetPath + '/js/bundle.min.js')
  tr.select('#my-css')<commit_msg>use system temp folder<commit_after>#!/usr/bin/env node
"use strict";
const fs = require('fs'),
  open = require('open'),
  trumpet = require('trumpet'),
  program = require('commander'),
  temp = require('temp'),
  jsStringEscape = require('js-string-escape'),
  columnsPageStream = require('json-columns-template'),
  currentVersion = require('./package.json').version;
 
// Process the data (note: error handling omitted) 
var myTemp = temp.open({suffix: '.html'});

//use the Commander package to parse user-supplied parameters and auto-generate a --help document
let inputPath;
program
  .version(currentVersion)
  .arguments('<path to JSON file>')
  .action(function (path) {
    inputPath = path;
  })
  .parse(process.argv);

fs.readFile(inputPath, processData);

//will receive readable stream from fs.readFile
function processData(err, data) {
  if (err) {
    console.error(err);
  } else {
    const fileContents = data.toString();
    const escapedString = jsStringEscape(fileContents);
    
    checkForValidJson(fileContents);
    createPageWithData(escapedString, true);
  }
}

//abort the process and display an error msg if the provided user data isn't valid JSON
function checkForValidJson(string) {
  try {
    JSON.parse(string);
    return true;
  } catch (err) {
    if (err instanceof SyntaxError) {
      console.log('Error: not a valid JSON string. ', err.message);
    } else {
      console.log('Unexpected error.');
      console.error(err);
    }
    process.exit();
  }
}

function createPageWithData(userData, openPage) {
  const assetPath = __dirname + '/node_modules/json-columns-template/build';
  const tempFile = temp.path({suffix: '.html'});
  const tr = trumpet();
  
  //add code defining a variable to a blank script in source HTML file.
  tr.select('#preload-data')
    .createWriteStream()
    .end(`var preloadedUserData = '${userData}'`);

  //direct generated page to local versions of assets
  tr.select('#bundle')
    .setAttribute('src', assetPath + '/js/bundle.min.js')
  tr.select('#my-css')
{'fraction_non_alphanumeric': 0.14001937984496124, 'fraction_numerical': 0.0, 'mean_word_length': 3.8348946135831383, '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': '5542061', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1242, 'n_words': 340}