UNPKG

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