index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var utils = require('../utils');
  3. var add = require('./add');
  4. var parse = require('./parse');
  5. // exported
  6. var rules = { ignore: [], watch: [] };
  7. /**
  8. * Loads a nodemon config file and populates the ignore
  9. * and watch rules with it's contents, and calls callback
  10. * with the new rules
  11. *
  12. * @param {String} filename
  13. * @param {Function} callback
  14. */
  15. function load(filename, callback) {
  16. parse(filename, function (err, result) {
  17. if (err) {
  18. // we should have bombed already, but
  19. utils.log.error(err);
  20. callback(err);
  21. }
  22. if (result.raw) {
  23. result.raw.forEach(add.bind(null, rules, 'ignore'));
  24. } else {
  25. result.ignore.forEach(add.bind(null, rules, 'ignore'));
  26. result.watch.forEach(add.bind(null, rules, 'watch'));
  27. }
  28. callback(null, rules);
  29. });
  30. }
  31. module.exports = {
  32. reset: function () { // just used for testing
  33. rules.ignore.length = rules.watch.length = 0;
  34. delete rules.ignore.re;
  35. delete rules.watch.re;
  36. },
  37. load: load,
  38. ignore: {
  39. test: add.bind(null, rules, 'ignore'),
  40. add: add.bind(null, rules, 'ignore'),
  41. },
  42. watch: {
  43. test: add.bind(null, rules, 'watch'),
  44. add: add.bind(null, rules, 'watch'),
  45. },
  46. add: add.bind(null, rules),
  47. rules: rules,
  48. };