<commit_before>const yaml = require('js-yaml')
const deferred = require('deferred')
const os = require('os')
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const _ = require('lodash')
const promisify = deferred.promisify

const readFileAsync = promisify(fs.readFile)
const mkdirpAsync = promisify(mkdirp)

const argv = require('yargs').default('config', '../config/local-config.yaml').argv
const defaultConfig = {
  'deviceId': '',
  'ffmpegOverridePath': '',
  'tmpDirectory': path.join(os.homedir(), '/graybox'),
  'loggingPath': path.join(os.homedir(), '/graybox/logs'),
  'verboseFfmpeg': false
}

module.exports =
{
  load: function () {
    const d = deferred()
    const configLocation = argv.config

    readFileAsync(configLocation, 'utf8')
      .then(function (result) {
        const tmpConfig = _.merge(defaultConfig, _.omitBy(yaml.safeLoad(result), _.isEmpty))
        console.log('verbose ffmpeg', tmpConfig.verboseFfmpeg)
        return mkdirpAsync(tmpConfig.tmpDirectory).then(() => mkdirpAsync(tmpConfig.loggingPath)).then(() => tmpConfig)
      }).done(function (config) {
        d.resolve(config)
      }, function (err) {
        d.reject(err)
      })
    return d.promise<commit_msg>better local config loading<commit_after>const yaml = require('js-yaml')
const deferred = require('deferred')
const os = require('os')
const fs = require('fs')
const path = require('path')
const mkdirp = require('mkdirp')
const _ = require('lodash')
const promisify = deferred.promisify

const readFileAsync = promisify(fs.readFile)
const mkdirpAsync = promisify(mkdirp)

const argv = require('yargs').default('config', '../config/local-config.yaml').argv
const defaultConfig = {
  'deviceId': null,
  'ffmpegOverridePath': null,
  'tmpDirectory': path.join(os.homedir(), '/graybox'),
  'loggingPath': path.join(os.homedir(), '/graybox/logs'),
  'verboseFfmpeg': false
}

module.exports =
{
  load: function () {
    const d = deferred()
    const configLocation = argv.config

    readFileAsync(configLocation, 'utf8')
      .then(function (result) {
        const tmpConfig = _.merge(defaultConfig, _.omitBy(yaml.safeLoad(result), _.isNil))
        console.log('verbose ffmpeg', tmpConfig.verboseFfmpeg)
        return mkdirpAsync(tmpConfig.tmpDirectory).then(() => mkdirpAsync(tmpConfig.loggingPath)).then(() => tmpConfig)
      }).done(function (config) {
        d.resolve(config)
      }, function (err) {
        d.reject(err)
      })
    return d.promise
{'fraction_non_alphanumeric': 0.15617529880478087, 'fraction_numerical': 0.0007968127490039841, 'mean_word_length': 4.20954356846473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6582551', 'n_tokens_mistral': 802, 'n_tokens_neox': 786, 'n_words': 160}