mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Fix a return value of RcParser.parse
This commit is contained in:
@@ -64,24 +64,12 @@ function get () {
|
|||||||
let config = window.localStorage.getItem('config')
|
let config = window.localStorage.getItem('config')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const homePath = global.process.env.HOME || global.process.env.USERPROFILE
|
const boostnotercConfig = RcParser.parse()
|
||||||
const boostnotercPath = path.join(homePath, BOOSTNOTERC)
|
|
||||||
const boostnotercConfig = RcParser.parse(boostnotercPath)
|
|
||||||
|
|
||||||
config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config))
|
config = Object.assign({}, DEFAULT_CONFIG, JSON.parse(config))
|
||||||
|
|
||||||
if (boostnotercConfig !== undefined) {
|
config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig)
|
||||||
config = Object.assign({}, DEFAULT_CONFIG, boostnotercConfig)
|
config = assignConfigValues(config, boostnotercConfig, config)
|
||||||
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)
|
|
||||||
|
|
||||||
if (!validate(config)) throw new Error('INVALID CONFIG')
|
if (!validate(config)) throw new Error('INVALID CONFIG')
|
||||||
} catch (err) {
|
} 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 {
|
export default {
|
||||||
get,
|
get,
|
||||||
set,
|
set,
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import _ from 'lodash'
|
import path from 'path'
|
||||||
|
import sander from 'sander'
|
||||||
|
|
||||||
const path = require('path')
|
function parse () {
|
||||||
const sander = require('sander')
|
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 {}
|
||||||
if (!sander.existsSync(boostnotercPath)) return
|
return JSON.parse(sander.readFileSync(boostnotercPath).toString())
|
||||||
let config = JSON.parse(sander.readFileSync(boostnotercPath).toString())
|
|
||||||
return config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec (boostnotercPath) {
|
function exec (boostnotercPath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user