-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings_migrator.js
34 lines (30 loc) · 1.02 KB
/
settings_migrator.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
"use strict";
const DefaultSettings = {
loginDelay: 1500,
messageDelay: 4000,
messageStyleIndex: 0,
};
// from_ver, to_ver = version number; settings = "old settings"
module.exports = function MigrateSettings(from_ver, to_ver, settings) {
let defaultCopy = Object.assign({}, DefaultSettings);
if (from_ver === null) {
// No config file exists or corrupted file, use default settings
return DefaultSettings;
} else if (from_ver === undefined) {
// Migrate legacy config file
return Object.assign(defaultCopy, settings);
} else {
return Object.assign(defaultCopy, settings);
}
};
function notEmptyObject(obj) {
return obj !== null && typeof obj === 'object' && Object.keys(obj).length;
}
// only set add -> add
// only set remove -> remove
// set both -> replace/update
const commitsByVersion = new Map([
[1, { add: { loginDelay: 1500 }, remove: {} }],
[2, { add: { messageDelay: 4000 }, remove: {} }],
[3, { add: { messageStyleIndex: 0 }, remove: {}}]
]);