Skip to content

Commit

Permalink
refactor: better template string migration
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 16, 2021
1 parent 18e35bf commit dae58a4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,6 @@ export function migrateConfig(
if (subMigrate.isMigrated) {
migratedConfig[key] = subMigrate.migratedConfig;
}
} else if (
(key.startsWith('commitMessage') || key.startsWith('prTitle')) &&
is.string(val)
) {
migratedConfig[key] = val
.replace(/currentVersion/g, 'currentValue')
.replace(/newVersion/g, 'newValue')
.replace(/newValueMajor/g, 'newMajor')
.replace(/newValueMinor/g, 'newMinor')
.replace(/newVersionMajor/g, 'newMajor')
.replace(/newVersionMinor/g, 'newMinor');
} else if (key === 'raiseDeprecationWarnings') {
delete migratedConfig.raiseDeprecationWarnings;
if (val === false) {
Expand All @@ -514,6 +503,22 @@ export function migrateConfig(
} else if (key === 'binarySource' && val === 'auto') {
migratedConfig.binarySource = 'global';
}
const migratedTemplates = {
currentVersion: 'currentValue',
newVersion: 'newValue',
newValueMajor: 'newMajor',
newValueMinor: 'newMinor',
newVersionMajor: 'newMajor',
newVersionMinor: 'newMinor',
};
if (is.string(migratedConfig[key])) {
for (const [from, to] of Object.entries(migratedTemplates)) {
migratedConfig[key] = (migratedConfig[key] as string).replace(
new RegExp(from, 'g'),
to
);
}
}
}
if (migratedConfig.endpoints) {
migratedConfig.hostRules = migratedConfig.endpoints;
Expand Down

0 comments on commit dae58a4

Please sign in to comment.