1 | 'use strict'
|
2 |
|
3 | const { normalizeFunctionsProps, WILDCARD_ALL } = require('./functions_config')
|
4 | const { mergeConfigs } = require('./merge')
|
5 | const { DEFAULT_ORIGIN } = require('./origin')
|
6 | const { removeFalsy } = require('./utils/remove_falsy')
|
7 |
|
8 |
|
9 | const 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 |
|
18 |
|
19 |
|
20 | const removeEmpty = function ({ build, ...config }) {
|
21 | return removeFalsy({ ...config, build: removeFalsy(build) })
|
22 | }
|
23 |
|
24 | const 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 |
|
36 | const normalizePlugin = function ({ inputs = {}, ...plugin }) {
|
37 | return removeFalsy({ ...plugin, inputs })
|
38 | }
|
39 |
|
40 | module.exports = { normalizeConfig }
|