Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function getConfig(
configParam: string | StyleguidistConfig | { serverPort?: string | number },
update?: (conf: StyleguidistConfig | {}) => StyleguidistConfig
): StyleguidistConfig {
let configFilepath
let config: StyleguidistConfig | { serverPort?: string | number }
if (isString(configParam)) {
// Load config from a given file
configFilepath = path.resolve(process.cwd(), configParam)
if (!fs.existsSync(configFilepath)) {
throw new StyleguidistError('Styleguidist config not found: ' + configFilepath + '.')
}
config = {}
} else if (!isPlainObject(configParam)) {
// Try to read config options from a file
configFilepath = findConfigFile()
config = {}
} else {
config = configParam
}
if (typeof configFilepath === 'string') {
config = require(configFilepath)
}
if (update) {
config = update(config)
process: (value: any) => {
if (typeof value === 'string') {
throw new StyleguidistError(
`${kleur.bold(
'template'
)} config option format has been changed, you need to update your config.`,
'template'
)
}
return value
}
},