Skip to content

Commit

Permalink
Fix default config
Browse files Browse the repository at this point in the history
  • Loading branch information
tengattack committed Nov 21, 2016
1 parent 5ffcd2c commit 2f2f494
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
22 changes: 13 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ class HaneConfig {
}
}
constructor(root) {
let config;
try {
const configPath = _path2.default.join(root, 'hane.yml');
const data = fs.readFileSync(configPath, 'utf8');
config = _jsYaml2.default.safeLoad(data);
config = (0, _lodash.pick)(config, configValidFields);
config = _extends({}, HaneConfig.defaultConfig, config);
} catch (e) {
config = (0, _lodash.cloneDeep)(HaneConfig.defaultConfig);
let config = HaneConfig.defaultConfig ? (0, _lodash.cloneDeep)(HaneConfig.defaultConfig) : {};

if (root) {
try {
const configPath = _path2.default.join(root, 'hane.yml');
const data = fs.readFileSync(configPath, 'utf8');
const _config = _jsYaml2.default.safeLoad(data);
_config = (0, _lodash.pick)(_config, configValidFields);
config = _extends({}, config, _config);
} catch (e) {
config = (0, _lodash.cloneDeep)(HaneConfig.defaultConfig);
}
}

this.config = config;
}
get render() {
Expand Down
24 changes: 15 additions & 9 deletions src/index.es
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ class HaneConfig {
}
}
constructor(root) {
let config
try {
const configPath = path.join(root, 'hane.yml')
const data = fs.readFileSync(configPath, 'utf8')
config = yaml.safeLoad(data)
config = pick(config, configValidFields)
config = { ...HaneConfig.defaultConfig, ...config }
} catch (e) {
config = cloneDeep(HaneConfig.defaultConfig)
let config = HaneConfig.defaultConfig
? cloneDeep(HaneConfig.defaultConfig)
: {}

if (root) {
try {
const configPath = path.join(root, 'hane.yml')
const data = fs.readFileSync(configPath, 'utf8')
const _config = yaml.safeLoad(data)
_config = pick(_config, configValidFields)
config = { ...config, ..._config }
} catch (e) {
config = cloneDeep(HaneConfig.defaultConfig)
}
}

this.config = config
}
get render() {
Expand Down

0 comments on commit 2f2f494

Please sign in to comment.