1 | 'use strict';
|
2 | var fs = require('fs');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function 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 |
|
38 | return callback(null, { raw: content.split(/\n/) });
|
39 | });
|
40 | }
|
41 |
|
42 | module.exports = parse;
|
43 |
|