<commit_before>global.root_require = function root_require(p) { return require(require('path').join(__dirname, p)); }

var path = require('path');
var config = require('./config');
var build = require('./lib/build');
var Bucket = require('./lib/bucket');

if(process.argv.length < 3) {
  console.log('Usage: node build.js id [dev, push]');
  return;
}

var id = process.argv[2];
var user = config.users[id];

var staging_dir = path.join(config.source, id.toString());
var build_dir = path.join(config.destination, id.toString());
var middleware = (user && user.middleware(staging_dir)) || [] ;

var is_dev = false;
var is_push = false;

if(process.argv.length > 3) {
  is_dev = process.argv[3] === 'dev';
  is_push = process.argv[3] === 'push';
}

var is_script = !module.parent;

if(is_script) {
  build(config.root, staging_dir, build_dir, middleware, is_dev).then(function(result) {
    return is_push ? new Bucket(build_dir, user.bucket).push() : result;
  }).done();
}
<commit_msg>Updating build script with a fetch utility<commit_after>global.root_require = function root_require(p) { return require(require('path').join(__dirname, p)); }

var path = require('path');
var config = require('./config');
var build = require('./lib/build');
var Bucket = require('./lib/bucket');
var Dropbox = require('./lib/dropbox');
var store = new (require('./lib/store'))(config.key_bucket);

if(process.argv.length < 3) {
  console.log('Usage: node build.js id [dev, push]');
  return;
}

var id = process.argv[2];
var user = config.users[id];

var staging_dir = path.join(config.source, id.toString());
var build_dir = path.join(config.destination, id.toString());
var middleware = (user && user.middleware(staging_dir)) || [] ;

var is_dev = false;
var is_push = false;
var is_fetch = false;

if(process.argv.length > 3) {
  is_dev = process.argv[3] === 'dev';
  is_push = process.argv[3] === 'push';
  is_fetch = process.argv[3] === 'fetch';
}

var is_script = !module.parent;

if(is_fetch) {
  store.get(id).then(function(result) {
    return new Dropbox(result.Body.toString(), path.join(config.source, 'fetch')).sync();
  }).done();
}

if(is_script) {
  build(config.root, staging_dir, build_dir, middleware, is_dev).then(function(result) {
    return is_push ? new Bucket(build_dir, user.bucket).push() : result;
  }).done();
}

{'fraction_non_alphanumeric': 0.18607649333906318, 'fraction_numerical': 0.004727116458960034, 'mean_word_length': 4.89367088607595, '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': '7257565', 'n_tokens_mistral': 804, 'n_tokens_neox': 796, 'n_words': 177}