UNPKG

1.37 kBJavaScriptView Raw
1'use strict'
2
3const { addBuildSettings } = require('./api/build_settings')
4const { logDefaultConfig } = require('./log/main')
5
6// Retrieve default configuration file. It has less priority and it also does
7// not get normalized, merged with contexts, etc.
8const parseDefaultConfig = function ({ defaultConfig, base, baseRelDir, siteInfo, logs, debug }) {
9 const defaultConfigB = addDefaultConfigBase(defaultConfig, base)
10 const { defaultConfig: defaultConfigC, baseRelDir: baseRelDirA = DEFAULT_BASE_REL_DIR } = addBuildSettings({
11 defaultConfig: defaultConfigB,
12 baseRelDir,
13 siteInfo,
14 })
15 logDefaultConfig(defaultConfigC, { logs, debug, baseRelDir: baseRelDirA })
16 return { defaultConfig: defaultConfigC, baseRelDir: baseRelDirA }
17}
18
19// When the `base` was overridden, add it to `defaultConfig` so it behaves
20// as if it had been specified in the UI settings
21const addDefaultConfigBase = function (defaultConfig, base) {
22 if (base === undefined) {
23 return defaultConfig
24 }
25
26 const { build = {} } = defaultConfig
27 return { ...defaultConfig, build: { ...build, base } }
28}
29
30// `baseRelDir` should default to `true` only if the option was not passed and
31// it could be retrieved from the `siteInfo`, which is why the default value
32// is assigned later than other properties.
33const DEFAULT_BASE_REL_DIR = true
34
35module.exports = { parseDefaultConfig }