UNPKG

1.42 kBJavaScriptView Raw
1'use strict'
2
3const { normalizeFunctionsProps, WILDCARD_ALL } = require('./functions_config')
4const { mergeConfigs } = require('./merge')
5const { DEFAULT_ORIGIN } = require('./origin')
6const { removeFalsy } = require('./utils/remove_falsy')
7
8// Normalize configuration object
9const normalizeConfig = function (config) {
10 const configA = removeEmpty(config)
11 const { build, functions, plugins, ...configB } = mergeConfigs([DEFAULT_CONFIG, configA])
12 const { build: buildA, functions: functionsA, functionsDirectoryProps } = normalizeFunctionsProps(build, functions)
13 const pluginsA = plugins.map(normalizePlugin)
14 return { ...configB, build: buildA, functions: functionsA, plugins: pluginsA, ...functionsDirectoryProps }
15}
16
17// Remove empty strings.
18// This notably ensures that empty strings in the build command are removed.
19// Otherwise those would be run during builds, making the build fail.
20const removeEmpty = function ({ build, ...config }) {
21 return removeFalsy({ ...config, build: removeFalsy(build) })
22}
23
24const DEFAULT_CONFIG = {
25 build: {
26 environment: {},
27 publish: '.',
28 publishOrigin: DEFAULT_ORIGIN,
29 processing: { css: {}, html: {}, images: {}, js: {} },
30 services: {},
31 },
32 functions: { [WILDCARD_ALL]: {} },
33 plugins: [],
34}
35
36const normalizePlugin = function ({ inputs = {}, ...plugin }) {
37 return removeFalsy({ ...plugin, inputs })
38}
39
40module.exports = { normalizeConfig }