Skip to content

Commit

Permalink
feat(antdsite): add error tip when pasing config.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyi7099 committed Jul 30, 2019
1 parent 65d20f7 commit df05e57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/antdsite/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
var path = require('path');
var defaultConfig = require(path.resolve(__dirname, '../__default__/default-config'));
const path = require('path');
const defaultConfig = require(path.resolve(__dirname, '../__default__/default-config'));
const chalk = require('chalk');

const configName = '.antdsite.js';
let userConfig;

module.exports.getUserConfig = () => {
var config = {};
if (userConfig) return userConfig;

let configPath;

try {
config = require(path.resolve(configName));
configPath = path.resolve(configName);
userConfig = require(configPath);
} catch (error) {
config = defaultConfig;
console.error(
chalk.red(
`[AntdSite]: Error when parsing ${configName} at ${configPath}, fallback to default config, the detail error is bellow:`
)
);
console.error(error);
userConfig = defaultConfig;
}

return config;
return userConfig;
};

function isObject(receive) {
Expand All @@ -35,7 +47,7 @@ function deepMerge(from, to) {
}

module.exports.getFinalConfig = function() {
var config = module.exports.getUserConfig();
const config = module.exports.getUserConfig();

// merge with default config.
const finalConfig = deepMerge(config, defaultConfig);
Expand Down
1 change: 1 addition & 0 deletions packages/antdsite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"antd": "^3.20.1",
"antd-tools": "^7.3.5",
"axios": "^0.18.0",
"chalk": "2.4.2",
"change-case": "^3.1.0",
"classnames": "^2.2.5",
"docsearch.js": "^2.6.3",
Expand Down

0 comments on commit df05e57

Please sign in to comment.