* @param {import('..').NodemonSettings | string} settings * @returns {import('..').Nodemon}
(settings)
| 22 | * @returns {import('..').Nodemon} |
| 23 | */ |
| 24 | function nodemon(settings) { |
| 25 | bus.emit('boot'); |
| 26 | nodemon.reset(); |
| 27 | |
| 28 | /** @type {import('..').NodemonSettings} */ |
| 29 | let options |
| 30 | |
| 31 | // allow the cli string as the argument to nodemon, and allow for |
| 32 | // `node nodemon -V app.js` or just `-V app.js` |
| 33 | if (typeof settings === 'string') { |
| 34 | settings = settings.trim(); |
| 35 | if (settings.indexOf('node') !== 0) { |
| 36 | if (settings.indexOf('nodemon') !== 0) { |
| 37 | settings = 'nodemon ' + settings; |
| 38 | } |
| 39 | settings = 'node ' + settings; |
| 40 | } |
| 41 | options = cli.parse(settings); |
| 42 | } else options = settings; |
| 43 | |
| 44 | // set the debug flag as early as possible to get all the detailed logging |
| 45 | if (options.verbose) { |
| 46 | utils.debug = true; |
| 47 | } |
| 48 | |
| 49 | if (options.help) { |
| 50 | if (process.stdout.isTTY) { |
| 51 | process.stdout._handle.setBlocking(true); // nodejs/node#6456 |
| 52 | } |
| 53 | console.log(help(options.help)); |
| 54 | if (!config.required) { |
| 55 | process.exit(0); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (options.version) { |
| 60 | version().then(function (v) { |
| 61 | console.log(v); |
| 62 | if (!config.required) { |
| 63 | process.exit(0); |
| 64 | } |
| 65 | }); |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | // nodemon tools like grunt-nodemon. This affects where |
| 70 | // the script is being run from, and will affect where |
| 71 | // nodemon looks for the nodemon.json files |
| 72 | if (options.cwd) { |
| 73 | // this is protection to make sure we haven't dont the chdir already... |
| 74 | // say like in cli/parse.js (which is where we do this once already!) |
| 75 | if (process.cwd() !== path.resolve(config.system.cwd, options.cwd)) { |
| 76 | process.chdir(options.cwd); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | config.load(options, function (config) { |
| 81 | if (!config.options.dump && !config.options.execOptions.script && |
searching dependent graphs…