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

var glob = require('glob'),
    express = require('express'),
    serveStatic = require('serve-static'),
    d3 = require('d3'),
    child = require('child_process'),
    webshot = require('webshot')

var argv = require('minimist')(process.argv.slice(2))

var port = 3870
var gistID = null

d3.queue(1)
  .defer(initServer)
  .defer(fileCheck)
  .defer(gitCheck)
  .defer(snapPreview)
  .defer(resizeThumb)
  .defer(gitUpload)
  .awaitAll(function(err, res){
    console.log(err || 'pictures pushed')

    process.exit()
  })


//directory should have index.html and no thumbnail.png or preview.png
function fileCheck(cb){
  glob('*', {}, function(err, files){
    if (!err && !~files.indexOf('index.html'))    err = 'no index.html' 
    if (!err &&  ~files.indexOf('thumbnail.png')) err = 'thumbnail.png present' 
    if (!err &&  ~files.indexOf('preview.png'))   err = 'preview.png present' 
    cb(err)
  })
}


//make sure that working directory is in sync with origin/master
function gitCheck(cb){
  child.exec('git fetch && git status && git remote -v', function(err, stdout, stderr){
    if (!err && stderr) err = stderr
    if (!err && !~stdout.indexOf('On branch master')) err = 'not on master'
    if (!err && !~stdout.indexOf("Your branch is up-to-date with 'origin/master'.")) err = 'not synced with origin/master'
    if (!err && !~stdout.indexOf('nothing to commit, working directory clean')) err = 'uncommited local changes'

    if (!err) gistID = stdout.split('<EMAIL>:')[1].split('.git')[0]
    cb(err)
  })
}


//statically serve directory
function initServer(cb){
  var app = express()
  app.use(serveStatic('./', {'index': false}))  
  app.listen(port) 

  cb(null) 
}



function snapPreview(cb){
  var options = {
    screenSize: {width: 960, height: 500},
    shotSize:   {width: 960, height: 500},
    renderDelay: 5000
  }

  var url = argv.user ? 
    `http://bl.ocks.org/${argv.user}/raw/${gistID}` : 
    `http://localhost:${port}/index.html`
<commit_msg>fixes<commit_after>#!/usr/bin/env node

var glob = require('glob'),
    express = require('express'),
    serveStatic = require('serve-static'),
    d3 = require('d3'),
    child = require('child_process'),
    webshot = require('webshot')

var argv = require('minimist')(process.argv.slice(2))

var port = 3870
var gistID = null

d3.queue(1)
  .defer(initServer)
  .defer(fileCheck)
  .defer(gitCheck)
  .defer(snapPreview)
  .defer(resizeThumb)
  .defer(gitUpload)
  .awaitAll(function(err, res){
    console.log(err || 'pictures pushed')

    process.exit()
  })


//directory should have index.html and no thumbnail.png or preview.png
function fileCheck(cb){
  glob('*', {}, function(err, files){
    if (!err && !~files.indexOf('index.html'))    err = 'no index.html' 
    if (!err &&  ~files.indexOf('thumbnail.png')) err = 'thumbnail.png present' 
    if (!err &&  ~files.indexOf('preview.png'))   err = 'preview.png present' 
    cb(err)
  })
}


//make sure that working directory is in sync with origin/master
function gitCheck(cb){
  child.exec('git version && git fetch && git status && git remote -v', function(err, stdout, stderr){
    if (!err && stderr) 
      err = stderr
    if (!err && !~stdout.indexOf('git version 2'))
      err = 'gist-snap requires git version 2 '
    if (!err && !~stdout.indexOf('On branch master'))
      err = 'not on master'
    if (!err && !~stdout.indexOf("Your branch is up-to-date with 'origin/master'."))
      err = 'not synced with origin/master'
    if (!err && !~stdout.indexOf('nothing to commit, working directory clean'))
      err = 'uncommited local changes'

    if (!err) gistID = stdout.split('<EMAIL>:')[1].split('.git')[0]
    cb(err)
  })
}


//statically serve directory
function initServer(cb){
  var app = express()
  app.use(serveStatic('./', {'index': false}))  
  app.listen(port) 

  cb(null) 
}



function snapPreview(cb){
  var options = {
    screenSize: {width: 960, height: 500},
    shotSize:   {width: 960, height: 500},
    renderDelay: 5000
  }

  var url = argv.user ? 
    `http://bl.ocks.org/${argv.user}/raw/${gistID}` : 
    `http://localhost:${port}/index.html`

{'fraction_non_alphanumeric': 0.17645648525533444, 'fraction_numerical': 0.013426036921601535, 'mean_word_length': 3.4908503767491927, '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': '3445180', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1394, 'n_words': 353}