1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var debug = require('debug')('nodemon');
|
8 | var load = require('./load');
|
9 | var rules = require('../rules');
|
10 | var utils = require('../utils');
|
11 | var pinVersion = require('../version').pin;
|
12 | var command = require('./command');
|
13 | var rulesToMonitor = require('../monitor/match').rulesToMonitor;
|
14 | var bus = utils.bus;
|
15 |
|
16 | function reset() {
|
17 | rules.reset();
|
18 |
|
19 | config.dirs = [];
|
20 | config.options = { ignore: [], watch: [] };
|
21 | config.lastStarted = 0;
|
22 | config.loaded = [];
|
23 | }
|
24 |
|
25 | var config = {
|
26 | run: false,
|
27 | system: {
|
28 | cwd: process.cwd(),
|
29 | },
|
30 | required: false,
|
31 | dirs: [],
|
32 | timeout: 1000,
|
33 | options: {},
|
34 | };
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | config.load = function (settings, ready) {
|
46 | reset();
|
47 | var config = this;
|
48 | load(settings, config.options, config, function (options) {
|
49 | config.options = options;
|
50 |
|
51 | if (options.watch.length === 0) {
|
52 |
|
53 | options.watch.push('*.*');
|
54 | }
|
55 |
|
56 | if (options['watch_interval']) {
|
57 | options.watchInterval = options['watch_interval'];
|
58 | }
|
59 |
|
60 | config.watchInterval = options.watchInterval || null;
|
61 | if (options.signal) {
|
62 | config.signal = options.signal;
|
63 | }
|
64 |
|
65 | var cmd = command(config.options);
|
66 | config.command = {
|
67 | raw: cmd,
|
68 | string: utils.stringify(cmd.executable, cmd.args),
|
69 | };
|
70 |
|
71 |
|
72 | options.monitor = rulesToMonitor(options.watch, options.ignore, config);
|
73 |
|
74 | var cwd = process.cwd();
|
75 | debug('config: dirs', config.dirs);
|
76 | if (config.dirs.length === 0) {
|
77 | config.dirs.unshift(cwd);
|
78 | }
|
79 |
|
80 | bus.emit('config:update', config);
|
81 | pinVersion().then(function () {
|
82 | ready(config);
|
83 | }).catch(e => {
|
84 |
|
85 | console.error(e.stack);
|
86 | setTimeout(() => { throw e; }, 0);
|
87 | });
|
88 | });
|
89 | };
|
90 |
|
91 | config.reset = reset;
|
92 |
|
93 | module.exports = config;
|