UNPKG

804 BJavaScriptView Raw
1'use strict';
2var fs = require('fs');
3
4/**
5 * Parse the nodemon config file, supporting both old style
6 * plain text config file, and JSON version of the config
7 *
8 * @param {String} filename
9 * @param {Function} callback
10 */
11function parse(filename, callback) {
12 var rules = {
13 ignore: [],
14 watch: [],
15 };
16
17 fs.readFile(filename, 'utf8', function (err, content) {
18
19 if (err) {
20 return callback(err);
21 }
22
23 var json = null;
24 try {
25 json = JSON.parse(content);
26 } catch (e) {}
27
28 if (json !== null) {
29 rules = {
30 ignore: json.ignore || [],
31 watch: json.watch || [],
32 };
33
34 return callback(null, rules);
35 }
36
37 // otherwise return the raw file
38 return callback(null, { raw: content.split(/\n/) });
39 });
40}
41
42module.exports = parse;
43