All files ConfigTask.js

100% Statements 16/16
100% Branches 4/4
100% Functions 3/3
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38  1x 1x                       2x     1x 1x 1x     2x           2x 8x 8x   2x 1x     1x  
 
var fs = require('fs')
var sampleConfig = `
module.exports = {
  saveLocation: './dataFiles',
  unpackLocation: './unpackedFiles', // if not defined, defaults to 'unpackedFiles'
  apiUrl: 'https://api.inshosteddata.com/api',
  key: process.env.CD_API_KEY, // don't hardcode creds, keep them in environment variables ideally!
  secret: process.env.CD_API_SECRET,
  maxConnections: 200, // The maximum number of files allowed to be downloading simultaneously
}
`
class ConfigTask {
  constructor(opts, config, logger) {
    this.logger = logger
  }
  run(cb) {
    this.logger.info(sampleConfig)
    this.logger.info('was written to config.js')
    fs.writeFile('config.js.sample', sampleConfig, cb)
  }
  static validate(config) {
    var fields = [
      'saveLocation',
      'apiUrl',
      'key',
      'secret'
    ]
    var missing = []
    for (var field of fields) {
      if (!config[field]) missing.push(field)
    }
    if (missing.length) return `missing ${missing.join(', ')} fields in config`
    return null
  }
}
module.exports = ConfigTask