main
|
Last change
on this file since 2d1ec46 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
804 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 | var 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 | */
|
|---|
| 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 | // otherwise return the raw file
|
|---|
| 38 | return callback(null, { raw: content.split(/\n/) });
|
|---|
| 39 | });
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | module.exports = parse;
|
|---|
| 43 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.