-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathConfig.js
47 lines (37 loc) · 1.59 KB
/
Config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
const path = require('path');
const debug = require('debug')('tree');
class Config {
constructor(options) {
this.filename = options.filename;
this.directory = options.directory || options.root;
this.visited = options.visited || {};
this.nonExistent = options.nonExistent || [];
this.verbose = options.verbose;
this.isListForm = options.isListForm;
this.requireConfig = options.config || options.requireConfig;
this.webpackConfig = options.webpackConfig;
this.nodeModulesConfig = options.nodeModulesConfig;
this.detectiveConfig = options.detective || options.detectiveConfig || {};
this.tsConfig = options.tsConfig;
this.filter = options.filter;
if (!this.filename) { throw new Error('filename not given'); }
if (!this.directory) { throw new Error('directory not given'); }
if (this.filter && typeof this.filter !== 'function') { throw new Error('filter must be a function'); }
if ('string' === typeof this.tsConfig) {
debug('preparsing the ts config into an object for performance');
const ts = require('typescript');
const tsParsedConfig = ts.readJsonConfigFile(this.tsConfig, ts.sys.readFile);
const obj = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(this.tsConfig));
this.tsConfig = obj.raw;
}
debug('given filename: ' + this.filename);
this.filename = path.resolve(process.cwd(), this.filename);
debug('resolved filename: ' + this.filename);
debug('visited: ', this.visited);
}
clone () {
return new Config(this);
}
}
module.exports = Config;