* Discovers all the options required to run the script * and if a custom exec has been passed in, then it will * also try to work out what extensions to monitor and * whether there's a special way of running that script. * * @param {Object} nodemonOptions * @param {Object} execMap * @return
(nodemonOptions, execMap)
| 75 | * @return {Object} new and updated version of nodemonOptions |
| 76 | */ |
| 77 | function exec(nodemonOptions, execMap) { |
| 78 | if (!execMap) { |
| 79 | execMap = {}; |
| 80 | } |
| 81 | |
| 82 | var options = utils.clone(nodemonOptions || {}); |
| 83 | var script; |
| 84 | |
| 85 | // if there's no script passed, try to get it from the first argument |
| 86 | if (!options.script && (options.args || []).length) { |
| 87 | script = expandScript( |
| 88 | options.args[0], |
| 89 | options.ext && '.' + (options.ext || 'js').split(',')[0] |
| 90 | ); |
| 91 | |
| 92 | // if the script was found, shift it off our args |
| 93 | if (script !== options.args[0]) { |
| 94 | options.script = script; |
| 95 | options.args.shift(); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // if there's no exec found yet, then try to read it from the local |
| 100 | // package.json this logic used to sit in the cli/parse, but actually the cli |
| 101 | // should be parsed first, then the user options (via nodemon.json) then |
| 102 | // finally default down to pot shots at the directory via package.json |
| 103 | if (!options.exec && !options.script) { |
| 104 | var found = execFromPackage(); |
| 105 | if (found !== null) { |
| 106 | if (found.exec) { |
| 107 | options.exec = found.exec; |
| 108 | } |
| 109 | if (!options.script) { |
| 110 | options.script = found.script; |
| 111 | } |
| 112 | if (Array.isArray(options.args) && options.scriptPosition === null) { |
| 113 | options.scriptPosition = options.args.length; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // var options = utils.clone(nodemonOptions || {}); |
| 119 | script = path.basename(options.script || ''); |
| 120 | |
| 121 | var scriptExt = path.extname(script).slice(1); |
| 122 | |
| 123 | var extension = options.ext; |
| 124 | if (extension === undefined) { |
| 125 | var isJS = scriptExt === 'js' || scriptExt === 'mjs' || scriptExt === 'cjs'; |
| 126 | extension = isJS || !scriptExt ? 'js,mjs,cjs' : scriptExt; |
| 127 | extension += ',json'; // Always watch JSON files |
| 128 | } |
| 129 | |
| 130 | var execDefined = !!options.exec; |
| 131 | |
| 132 | // allows the user to simplify cli usage: |
| 133 | // https://github.com/remy/nodemon/issues/195 |
| 134 | // but always give preference to the user defined argument |
searching dependent graphs…