/
config.js
59 lines (48 loc) · 1.27 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
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
var path = require('path'),
fs = require('fs');
var defaultConfig = {
default: true,
docBlockRegex: /\/\*{2,}(.|[\r\n])+?\*\//g,
extensions: ['js'],
include: [],
exclude: ['node_modules', 'test'],
outputFile: 'README.md',
template: 'template.txt',
blockTemplate: 'block-template.txt'
};
var FILENAME = '.whatsupdocrc';
/**
* @name getConfig
* @description Get the config object, either from
* .whatsupdocrc or the default.
* @param {String} directory Where to look for config file.
* @return {Object}
*/
var getConfig = function (directory) {
var config = {};
var loadedConfig;
var file = path.join(directory, FILENAME);
var text;
var keys;
keys = Object.keys(defaultConfig);
keys.forEach(function (key) {
config[key] = defaultConfig[key];
});
try {
text = fs.readFileSync(file, 'utf-8');
} catch (e) {
// no config file found, use default
}
if (text) {
// Merge runtime config with settings.
loadedConfig = JSON.parse(text);
keys = Object.keys(loadedConfig);
keys.forEach(function (key) {
config[key] = loadedConfig[key];
});
delete config.default;
}
return config;
};
exports.getConfig = getConfig;