|
3 | 3 | const path = require('path');
|
4 | 4 | const debug = require('debug')('tree');
|
5 | 5 |
|
6 |
| -function Config(options) { |
7 |
| - this.filename = options.filename; |
8 |
| - this.directory = options.directory || options.root; |
9 |
| - this.visited = options.visited || {}; |
10 |
| - this.nonExistent = options.nonExistent || []; |
11 |
| - this.isListForm = options.isListForm; |
12 |
| - this.requireConfig = options.config || options.requireConfig; |
13 |
| - this.webpackConfig = options.webpackConfig; |
14 |
| - this.nodeModulesConfig = options.nodeModulesConfig; |
15 |
| - this.detectiveConfig = options.detective || options.detectiveConfig || {}; |
16 |
| - |
17 |
| - this.filter = options.filter; |
18 |
| - |
19 |
| - if (!this.filename) { throw new Error('filename not given'); } |
20 |
| - if (!this.directory) { throw new Error('directory not given'); } |
21 |
| - if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); } |
22 |
| - |
23 |
| - debug('given filename: ' + this.filename); |
24 |
| - |
25 |
| - this.filename = path.resolve(process.cwd(), this.filename); |
26 |
| - |
27 |
| - debug('resolved filename: ' + this.filename); |
28 |
| - debug('visited: ', this.visited); |
| 6 | +class Config { |
| 7 | + constructor(options) { |
| 8 | + this.filename = options.filename; |
| 9 | + this.directory = options.directory || options.root; |
| 10 | + this.visited = options.visited || {}; |
| 11 | + this.nonExistent = options.nonExistent || []; |
| 12 | + this.isListForm = options.isListForm; |
| 13 | + this.requireConfig = options.config || options.requireConfig; |
| 14 | + this.webpackConfig = options.webpackConfig; |
| 15 | + this.nodeModulesConfig = options.nodeModulesConfig; |
| 16 | + this.detectiveConfig = options.detective || options.detectiveConfig || {}; |
| 17 | + |
| 18 | + this.filter = options.filter; |
| 19 | + |
| 20 | + if (!this.filename) { throw new Error('filename not given'); } |
| 21 | + if (!this.directory) { throw new Error('directory not given'); } |
| 22 | + if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); } |
| 23 | + |
| 24 | + debug('given filename: ' + this.filename); |
| 25 | + |
| 26 | + this.filename = path.resolve(process.cwd(), this.filename); |
| 27 | + |
| 28 | + debug('resolved filename: ' + this.filename); |
| 29 | + debug('visited: ', this.visited); |
| 30 | + } |
| 31 | + |
| 32 | + clone () { |
| 33 | + return new Config(this); |
| 34 | + } |
29 | 35 | }
|
30 | 36 |
|
31 |
| -Config.prototype.clone = function() { |
32 |
| - return new Config(this); |
33 |
| -}; |
34 |
| - |
35 | 37 | module.exports = Config;
|
0 commit comments