Skip to content

Commit df05e57

Browse files
committed
feat(antdsite): add error tip when pasing config.
1 parent 65d20f7 commit df05e57

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

packages/antdsite/lib/util.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
var path = require('path');
2-
var defaultConfig = require(path.resolve(__dirname, '../__default__/default-config'));
1+
const path = require('path');
2+
const defaultConfig = require(path.resolve(__dirname, '../__default__/default-config'));
3+
const chalk = require('chalk');
34

45
const configName = '.antdsite.js';
6+
let userConfig;
57

68
module.exports.getUserConfig = () => {
7-
var config = {};
9+
if (userConfig) return userConfig;
10+
11+
let configPath;
12+
813
try {
9-
config = require(path.resolve(configName));
14+
configPath = path.resolve(configName);
15+
userConfig = require(configPath);
1016
} catch (error) {
11-
config = defaultConfig;
17+
console.error(
18+
chalk.red(
19+
`[AntdSite]: Error when parsing ${configName} at ${configPath}, fallback to default config, the detail error is bellow:`
20+
)
21+
);
22+
console.error(error);
23+
userConfig = defaultConfig;
1224
}
1325

14-
return config;
26+
return userConfig;
1527
};
1628

1729
function isObject(receive) {
@@ -35,7 +47,7 @@ function deepMerge(from, to) {
3547
}
3648

3749
module.exports.getFinalConfig = function() {
38-
var config = module.exports.getUserConfig();
50+
const config = module.exports.getUserConfig();
3951

4052
// merge with default config.
4153
const finalConfig = deepMerge(config, defaultConfig);

packages/antdsite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"antd": "^3.20.1",
2525
"antd-tools": "^7.3.5",
2626
"axios": "^0.18.0",
27+
"chalk": "2.4.2",
2728
"change-case": "^3.1.0",
2829
"classnames": "^2.2.5",
2930
"docsearch.js": "^2.6.3",

0 commit comments

Comments
 (0)