#884 Merging configuration updates to previous condifguration.

This commit is contained in:
knsv
2019-07-21 02:09:22 -07:00
parent 92ac7d7c24
commit b9ad9ba674
2 changed files with 30 additions and 6 deletions

View File

@@ -1,8 +1,29 @@
let config = { let config = {
securityLevel: 'strict'
} }
const setConf = function (cnf) {
// Top level initially mermaid, gflow, sequenceDiagram and gantt
const lvl1Keys = Object.keys(cnf)
for (let i = 0; i < lvl1Keys.length; i++) {
if (typeof cnf[lvl1Keys[i]] === 'object' && cnf[lvl1Keys[i]] != null) {
const lvl2Keys = Object.keys(cnf[lvl1Keys[i]])
for (let j = 0; j < lvl2Keys.length; j++) {
// logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j])
if (typeof config[lvl1Keys[i]] === 'undefined') {
config[lvl1Keys[i]] = {}
}
// logger.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]])
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]]
}
} else {
config[lvl1Keys[i]] = cnf[lvl1Keys[i]]
}
}
}
export const setConfig = conf => { export const setConfig = conf => {
config = conf setConf(conf)
} }
export const getConfig = () => config export const getConfig = () => config

View File

@@ -10,7 +10,7 @@
import * as d3 from 'd3' import * as d3 from 'd3'
import scope from 'scope-css' import scope from 'scope-css'
import pkg from '../package.json' import pkg from '../package.json'
import { setConfig } from './config' import { setConfig, getConfig } from './config'
import { logger, setLogLevel } from './logger' import { logger, setLogLevel } from './logger'
import utils from './utils' import utils from './utils'
import flowRenderer from './diagrams/flowchart/flowRenderer' import flowRenderer from './diagrams/flowchart/flowRenderer'
@@ -534,16 +534,19 @@ const setConf = function (cnf) {
function initialize (options) { function initialize (options) {
logger.debug('Initializing mermaidAPI ', pkg.version) logger.debug('Initializing mermaidAPI ', pkg.version)
// Update default config with options supplied at initialization // Update default config with options supplied at initialization
if (typeof options === 'object') { if (typeof options === 'object') {
setConf(options) setConf(options)
} }
setConfig(config)
setLogLevel(config.logLevel) setLogLevel(config.logLevel)
} }
function getConfig () { // function getConfig () {
return config // console.warn('get config')
} // return config
// }
const mermaidAPI = { const mermaidAPI = {
render, render,