-
Notifications
You must be signed in to change notification settings - Fork 554
/
Copy pathloader.js
60 lines (50 loc) · 1.66 KB
/
loader.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
48
49
50
51
52
53
54
55
56
57
58
59
60
import path from 'path';
import { findup, getContent } from '../configLoader';
import { isInTest } from '../common/util.js';
export default loader;
/**
* Command line config helpers
* Shamelessly ripped from with slight modifications:
* https://github.com/jscs-dev/node-jscs/blob/master/lib/cli-config.js
*/
/**
* Get content of the configuration file
* @param {String} config - partial path to configuration file
* @param {String} [cwd = process.cwd()] - directory path which will be joined with config argument
* @return {Object|undefined}
*/
function loader (configs, config, cwd) {
var content;
var directory = cwd || process.cwd();
// If config option is given, attempt to load it
if (config) {
return getContent(config, directory);
}
content = getContent(
findup(configs, { nocase: true, cwd: directory }, function (configPath) {
if (path.basename(configPath) === 'package.json') {
// return !!this.getContent(configPath);
}
return true;
})
);
if (content) {
return content;
}
/* istanbul ignore if */
if (!isInTest()) {
// Try to load standard configs from home dir
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
if (!directoryArr[i]) {
continue;
}
for (var j = 0, len = configs.length; j < len; j++) {
content = getContent(configs[j], directoryArr[i]);
if (content) {
return content;
}
}
}
}
}