/
seeder-configuration-merger.js
57 lines (51 loc) · 1.51 KB
/
seeder-configuration-merger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { FsSeeds } = require('./sources/fs-seeds');
const Logger = require('../../logger');
const { DEFAULT_LOAD_EXTENSIONS } = require('../common/MigrationsLoader');
const defaultLogger = new Logger();
const CONFIG_DEFAULT = Object.freeze({
extension: 'js',
directory: './seeds',
loadExtensions: DEFAULT_LOAD_EXTENSIONS,
specific: null,
timestampFilenamePrefix: false,
recursive: false,
sortDirsSeparately: false,
});
function getMergedConfig(config, currentConfig, logger = defaultLogger) {
// config is the user specified config, mergedConfig has defaults and current config
// applied to it.
const mergedConfig = Object.assign(
{},
CONFIG_DEFAULT,
currentConfig || {},
config
);
if (
config &&
// If user specifies any FS related config,
// clear specified migrationSource to avoid ambiguity
(config.directory ||
config.sortDirsSeparately !== undefined ||
config.loadExtensions)
) {
if (config.seedSource) {
logger.warn(
'FS-related option specified for seed configuration. This resets seedSource to default FsMigrations'
);
}
mergedConfig.seedSource = null;
}
// If the user has not specified any configs, we need to
// default to fs migrations to maintain compatibility
if (!mergedConfig.seedSource) {
mergedConfig.seedSource = new FsSeeds(
mergedConfig.directory,
mergedConfig.sortDirsSeparately,
mergedConfig.loadExtensions
);
}
return mergedConfig;
}
module.exports = {
getMergedConfig,
};