1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = void 0;
|
5 |
|
6 | var _fs = _interopRequireDefault(require("fs"));
|
7 |
|
8 | var _path = _interopRequireDefault(require("path"));
|
9 |
|
10 | var _findup = _interopRequireDefault(require("findup"));
|
11 |
|
12 | var _isString = _interopRequireDefault(require("lodash/isString"));
|
13 |
|
14 | var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
15 |
|
16 | var _config = _interopRequireDefault(require("./schemas/config"));
|
17 |
|
18 | var _error = _interopRequireDefault(require("./utils/error"));
|
19 |
|
20 | var _sanitizeConfig = _interopRequireDefault(require("./utils/sanitizeConfig"));
|
21 |
|
22 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23 |
|
24 | const CONFIG_FILENAME = 'styleguide.config.js';
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function findConfigFile() {
|
32 | let configDir;
|
33 |
|
34 | try {
|
35 | configDir = _findup.default.sync(process.cwd(), CONFIG_FILENAME);
|
36 | } catch (exception) {
|
37 | return false;
|
38 | }
|
39 |
|
40 | return _path.default.join(configDir, CONFIG_FILENAME);
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | function getConfig(config, update) {
|
52 | let configFilepath = false;
|
53 |
|
54 | if ((0, _isString.default)(config)) {
|
55 |
|
56 | configFilepath = _path.default.resolve(process.cwd(), config);
|
57 |
|
58 | if (!_fs.default.existsSync(configFilepath)) {
|
59 | throw new _error.default('Styleguidist config not found: ' + configFilepath + '.');
|
60 | }
|
61 |
|
62 | config = {};
|
63 | } else if (!(0, _isPlainObject.default)(config)) {
|
64 |
|
65 | configFilepath = findConfigFile();
|
66 | config = {};
|
67 | }
|
68 |
|
69 | if (configFilepath) {
|
70 | config = require(configFilepath);
|
71 | }
|
72 |
|
73 | if (!config || (0, _isString.default)(config)) {
|
74 | return {};
|
75 | }
|
76 |
|
77 | if (update) {
|
78 | config = update(config);
|
79 | }
|
80 |
|
81 | const configDir = configFilepath ? _path.default.dirname(configFilepath) : process.cwd();
|
82 |
|
83 | try {
|
84 | return (0, _sanitizeConfig.default)(config, _config.default, configDir);
|
85 | } catch (exception) {
|
86 | if (exception instanceof _error.default) {
|
87 | throw new _error.default(`Something is wrong with your style guide config\n\n${exception.message}`, exception.extra);
|
88 | } else {
|
89 | throw exception;
|
90 | }
|
91 | }
|
92 | }
|
93 |
|
94 | var _default = getConfig;
|
95 | exports.default = _default; |
\ | No newline at end of file |