DemocracyOS/democracyos

View on GitHub
bin/dos-install

Summary

Maintainability
Test Coverage
#!/usr/bin/env node

/**
 * Module dependencies.
 */
var fs = require('fs')
var exists = fs.existsSync
var write = fs.writeFileSync
var path = require('path')
var resolve = path.resolve
var crypto = require('crypto')
var program = require('commander')
var env = process.env.NODE_ENV || 'development'

program
  .option('-c, --config', 'copy and/or merge configuration file')
  .parse(process.argv)

/**
 * Make sure there is a config file
 */

if (program.config && env !== 'production') {
  var dest = resolve('./config/' + env + '.json')
  if (!exists(dest)) {
    console.log('Creating ' + dest)
    var defaults = require(resolve('./config/defaults'))

    var config = {
      jwtSecret: crypto.randomBytes(32).toString('hex')
    }

    ;[
      'protocol',
      'host',
      'publicPort',
      'mongoUrl',
      'locale',
      'organizationName',
      'organizationUrl'
    ].forEach(function (key) {
      config[key] = defaults[key]
    })

    write(dest, JSON.stringify(config, null, 2))
  }
}