From b7b715ba3dd45ae16ee6026f9ce7b81425c3a380 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Thu, 10 Aug 2017 09:43:04 +0900 Subject: [PATCH] Fix a return value of RcParser.parse --- browser/main/lib/ConfigManager.js | 26 +++++++++++--------------- browser/main/lib/RcParser.js | 15 ++++++++------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 8069ce0a..53a93a72 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -64,24 +64,12 @@ function get () { let config = window.localStorage.getItem('config') try { - const homePath = global.process.env.HOME || global.process.env.USERPROFILE - const boostnotercPath = path.join(homePath, BOOSTNOTERC) - const boostnotercConfig = RcParser.parse(boostnotercPath) + const boostnotercConfig = RcParser.parse() config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config)) - if (boostnotercConfig !== undefined) { - config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig) - config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, boostnotercConfig.hotkey) - config.ui = Object.assign({}, DEFAULT_CONFIG.ui, boostnotercConfig.ui) - config.editor = Object.assign({}, DEFAULT_CONFIG.editor, boostnotercConfig.editor) - config.preview = Object.assign({}, DEFAULT_CONFIG.preview, boostnotercConfig.preview) - } - - config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, config.hotkey) - config.ui = Object.assign({}, DEFAULT_CONFIG.ui, config.ui) - config.editor = Object.assign({}, DEFAULT_CONFIG.editor, config.editor) - config.preview = Object.assign({}, DEFAULT_CONFIG.preview, config.preview) + config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig) + config = assignConfigValues(config, boostnotercConfig, config) if (!validate(config)) throw new Error('INVALID CONFIG') } catch (err) { @@ -144,6 +132,14 @@ function set (updates) { }) } +function assignConfigValues (config, rcConfig, originalConfig) { + config.hotkey = Object.assign({}, DEFAULT_CONFIG.hotkey, rcConfig, originalConfig.hotkey) + config.ui = Object.assign({}, DEFAULT_CONFIG.ui, rcConfig, originalConfig.ui) + config.editor = Object.assign({}, DEFAULT_CONFIG.editor, rcConfig, originalConfig.editor) + config.preview = Object.assign({}, DEFAULT_CONFIG.preview, rcConfig, originalConfig.preview) + return config +} + export default { get, set, diff --git a/browser/main/lib/RcParser.js b/browser/main/lib/RcParser.js index 031b3a1d..6653847f 100644 --- a/browser/main/lib/RcParser.js +++ b/browser/main/lib/RcParser.js @@ -1,12 +1,13 @@ -import _ from 'lodash' +import path from 'path' +import sander from 'sander' -const path = require('path') -const sander = require('sander') +function parse () { + const BOOSTNOTERC = '.boostnoterc' + const homePath = global.process.env.HOME || global.process.env.USERPROFILE + const boostnotercPath = path.join(homePath, BOOSTNOTERC) -function parse (boostnotercPath) { - if (!sander.existsSync(boostnotercPath)) return - let config = JSON.parse(sander.readFileSync(boostnotercPath).toString()) - return config + if (!sander.existsSync(boostnotercPath)) return {} + return JSON.parse(sander.readFileSync(boostnotercPath).toString()) } function exec (boostnotercPath) {