forked from tv2/sisyfos-audio-controller
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migration - handler updates from 4.xx to 4.6 and also .shot fil…
…es from 3.xx
- Loading branch information
Showing
3 changed files
with
82 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,72 @@ | ||
//@ts-ignore | ||
import { version } from '../../package.json' | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
import { logger } from './logger' | ||
import { ISettings } from '../reducers/settingsReducer' | ||
import { getSnapShotList, IShotStorage, saveSettings } from './SettingsStorage' | ||
|
||
export const checkVersion = (currentSettings: ISettings) => { | ||
if (currentSettings.sisyfosVersion < version) { | ||
migrateVersion(currentSettings) | ||
} | ||
} | ||
const version = process.env.npm_package_version | ||
|
||
export const getVersion = (): string => { | ||
return version | ||
export const checkVersion = (currentSettings: ISettings): ISettings => { | ||
if (version > (currentSettings.sisyfosVersion || '0')) { | ||
currentSettings = migrateVersion(currentSettings) | ||
} | ||
return currentSettings | ||
} | ||
|
||
const migrateVersion = (currentSettings: ISettings) => { | ||
const migrateVersion = (currentSettings: ISettings): ISettings => { | ||
console.log( | ||
'Migrating VERSION from', | ||
currentSettings.sisyfosVersion, | ||
' to ', | ||
version | ||
) | ||
let newSettings = currentSettings | ||
if (version === '4.6.0') { | ||
newSettings = migrate45to46(currentSettings) | ||
} | ||
return newSettings | ||
} | ||
|
||
const migrate45to46 = (currentSettings: ISettings): ISettings => { | ||
let files: string[] = getSnapShotList() | ||
files.push('default.shot') | ||
|
||
files.forEach((fileName: string) => { | ||
let stateFromShot = JSON.parse( | ||
fs.readFileSync(path.resolve('storage', fileName)) | ||
) | ||
// As this is the first implemented migration it also looks .shot files from ealier versions than 4.xx | ||
if (stateFromShot.channelState.chConnection) { | ||
// From Version 4.0 | ||
stateFromShot.channelState.chMixerConnection = | ||
stateFromShot.channelState?.chConnection | ||
delete stateFromShot.channelState.chConnection | ||
} else if (stateFromShot.channelState.channel) { | ||
// Version lower than 4.0 | ||
stateFromShot.channelState.chMixerConnection = [ | ||
{ channel: stateFromShot.channelState.channel }, | ||
] | ||
delete stateFromShot.channelState.channel | ||
} | ||
let migratedShot: IShotStorage = stateFromShot | ||
fs.writeFileSync( | ||
path.resolve('storage', fileName), | ||
JSON.stringify(migratedShot), | ||
'utf8', | ||
(error: any) => { | ||
if (error) { | ||
logger.error('Error saving Snapshot' + String(error), {}) | ||
} else { | ||
logger.verbose( | ||
'Snapshot ' + fileName + ' Saved to storage folder', | ||
{} | ||
) | ||
} | ||
} | ||
) | ||
}) | ||
currentSettings.sisyfosVersion = version | ||
saveSettings(currentSettings) | ||
return currentSettings | ||
} |