<commit_before><commit_msg>Added experimental updating<commit_after>const fs = require('fs')
const https = require('https')
const admzip = require('adm-zip')
const Promise = require('promise')
const bracketteData = require('../brackette-info.json')
const downloadRelease = require('download-github-release');
/**
 * Begging by brackette.json with that of the brackette.json from GitHub.
*/
downloadJson.call()
.then(decide)

/**
 * Fetches and reads the brackette.json from GitHub.
 */
function downloadJson() {
  const promise = new Promise((resolve, reject) => {
    const request = https.request(bracketteData.jsonPath, (res) => {
      let data = ''
      res.on('data', (d) => {
        data = data + d
      })
      res.on('end', () => {
        try {
          data = JSON.parse(data)
        } catch (e) {
          const err = new Error(e);
          reject(err)
          return;
        }
        resolve(data)
      })
    })
    request.on('error', (e) => {
      reject(e)
    })
    request.end()
  })
  return promise
}

/**
 * Decides what our course of action should be.
 */
function decide(data) {
  console.dir(data)
  const actualVersion = data.version;
  if(actualVersion == bracketteData.version) {
    console.info("You have the latest version: " + data.version);
    return Promise.reject("You have the latest version: " + data.version);
  }
  console.info("You are out of date. Updating now.");
  downloadRelease(bracketteData.user, bracketteData.repo, bracketteData.outputdir, filterRelease, filterAsset)
  .then(function() {
    console.log('All done!');
  })
  .catch(function(err) {
    console.log('oh noooo')
    console.error(err.message);
    // Assuming this worked...
    const zipname = `brackette-${actualVersion}.zip`
    if (fs.existsSync('../' + zipname)){
      // it exists so let's go!
      console.log('please wait...');
      const zip = new admzip('../' + zipname)
      const zipEntries = zip.getEntries();
      zip.extractAllTo('../', true);
      fs.unlink('../' + zipname);
      console.log('done')
    } else {
      console.error("There was an error! Could not find the zip file that we need...");
    }
  });
}


// Define a function to filter releases.
function filterRelease(release) {
  // Filter out prereleases.
  return release.prerelease === true;
}

// Define a function to filter assets.
function filterAsset(asset) {
  // Select assets that contain the string 'windows'.
  return asset.name.indexOf(`brackette-`) >= 0;
}
{'fraction_non_alphanumeric': 0.15152733118971062, 'fraction_numerical': 0.00040192926045016077, 'mean_word_length': 2.8589147286821706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2180581', 'n_tokens_mistral': 769, 'n_tokens_neox': 751, 'n_words': 199}