Code coverage report for lib/config/index.js

Statements: 96% (24 / 25)      Branches: 50% (3 / 6)      Functions: 100% (4 / 4)      Lines: 96% (24 / 25)     

All files » lib/config/ » index.js
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 751             1             1 3   3 3 3 3     1                                             1 3 3 3 3   3   3 3 3       3 3     3 3         1   1    
'use strict';
/**
 * Manages the internal config of nodemon, checking for the state of support
 * with fs.watch, how nodemon can watch files (using find or fs methods).
 *
 * This is *not* the user's config.
 */
var load = require('./load'),
    rules = require('../rules'),
    utils = require('../utils'),
    rulesToMonitor = require('../monitor/match').rulesToMonitor,
    bus = utils.bus,
    checkWatchSupport = require('./checkWatchSupport');
 
function reset() {
  rules.reset();
 
  config.dirs = [];
  config.options = { ignore: [], watch: [] };
  config.lastStarted = 0;
  config.loaded = [];
}
 
var config = {
  run: false,
  system: {
    cwd: process.cwd(),
    useFind: false,
    useWatch: false,
    useWatchFile: false,
  },
  required: false,
  dirs: [],
  timeout: 1000,
  options: {}
};
 
/**
 * Take user defined settings, then detect the local machine capability, then
 * look for local and global nodemon.json files and merge together the final
 * settings with the config for nodemon.
 *
 * @param  {Object} settings user defined settings for nodemon (typically on
 *  the cli)
 * @param  {Function} ready callback fired once the config is loaded
 */
config.load = function (settings, ready) {
  reset();
  var config = this;
  load(settings, config.options, config, function (options) {
    config.options = options;
 
    options.monitor = rulesToMonitor(options.watch, options.ignore, config);
 
    var cwd = process.cwd();
    Eif (config.dirs.length === 0) {
      config.dirs.unshift(cwd);
    }
 
    // now run automatic checks on system adding to the config object
    checkWatchSupport(config, function (config) {
      Iif (config.system.useFind === false && config.system.useWatch === false) {
        config.system.useWatchFile = true;
      }
      bus.emit('config:update', config);
      ready(config);
    });
  });
};
 
config.reset = reset;
 
module.exports = config;