UNPKG

1.54 kBJavaScriptView Raw
1var fs = require('fs');
2var path = require('path');
3
4function read(dir) {
5 var f = path.resolve(dir, '.node-dev.json');
6 return fs.existsSync(f) ? JSON.parse(fs.readFileSync(f, 'utf-8')) : null;
7}
8
9function resolvePath(unresolvedPath) {
10 return path.resolve(process.cwd(), unresolvedPath);
11}
12
13module.exports = function (main, opts) {
14
15 var dir = main ? path.dirname(main) : '.';
16 var c = read(dir)
17 || read(process.cwd())
18 || read(process.env.HOME || process.env.USERPROFILE) || {};
19
20 // Truthy == --all-deps, false: one level of deps
21 if (typeof c.deps !== 'number') c.deps = c.deps ? -1 : 1;
22
23 if (opts) {
24 // Overwrite with CLI opts ...
25 if (opts.allDeps) c.deps = -1;
26 if (!opts.deps) c.deps = 0;
27 if (opts.dedupe) c.dedupe = true;
28 if (opts.respawn) c.respawn = true;
29 if (opts.notify === false) c.notify = false;
30 if (opts.clear || opts.cls) c.clear = true;
31 }
32
33 var ignoreWatch = ([]).concat(opts && opts['ignore-watch'] || []).concat(c.ignore || []);
34 opts.debug && console.log('Ignore watch:', ignoreWatch)
35 var ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath));
36 return {
37 vm: c.vm !== false,
38 fork: c.fork !== false,
39 notify: c.notify !== false,
40 deps: c.deps,
41 timestamp: c.timestamp || (c.timestamp !== false && 'HH:MM:ss'),
42 clear: !!(c.clear),
43 dedupe: !!c.dedupe,
44 ignore: ignore,
45 respawn: c.respawn || false,
46 debug: opts.debug,
47 extensions: c.extensions || {
48 coffee: 'coffee-script/register',
49 ls: 'LiveScript'
50 }
51 };
52};