Skip to content

Commit

Permalink
feat: inital migration.ts and version check.
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Mar 23, 2021
1 parent 878df56 commit 15e9b79
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 31 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"@types/hoist-non-react-statics": "^3.3.1",
"@types/jest": "^26.0.20",
"@types/jquery": "^3.5.5",
"@types/node": "^14.14.35",
"@types/rc-slider": "^8.6.6",
"@types/react-redux": "^7.1.16",
"@types/react-select": "^4.0.13",
Expand All @@ -104,6 +105,7 @@
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.3.1",
"jest": "^26.6.3",
"json-loader": "^0.5.7",
"lint-staged": "^10.5.4",
"node-license-validator": "^1.3.0",
"prettier": "^2.2.1",
Expand Down
5 changes: 5 additions & 0 deletions server/reducers/settingsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import {
SET_PAGES_LIST,
TOGGLE_SHOW_CHAN_STRIP_FULL,
} from '../reducers/settingsActions'
import { getVersion } from '../utils/migrations'

export enum PageType {
All,
CustomPage,
}

export interface ISettings {
/* Sisyfos Settings Version: */
sisyfosVersion?: string

/** UI state (non persistant) */
showSettings: boolean
showPagesSetup: boolean
Expand Down Expand Up @@ -80,6 +84,7 @@ export interface IMixerSettings {

const defaultSettingsReducerState: Array<ISettings> = [
{
sisyfosVersion: getVersion(),
showSettings: false,
showPagesSetup: false,
showChanStrip: -1,
Expand Down
1 change: 1 addition & 0 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"esModuleInterop": true,
// Check for "any" while converting to TS this can be turned off.
"noImplicitAny": true,
"resolveJsonModule": true,
"module": "commonjs",
"outDir": "../dist/server"
},
Expand Down
5 changes: 4 additions & 1 deletion server/utils/SettingsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require('fs')
const path = require('path')
import { store } from '../reducers/store'
import { checkVersion } from './migrations'

// Redux:
import { storeSetCompleteChState } from '../reducers/channelActions'
Expand All @@ -14,9 +15,11 @@ import { ICustomPages } from '../reducers/settingsReducer'
export const loadSettings = (storeRedux: any) => {
let settingsInterface = storeRedux.settings[0]
try {
return JSON.parse(
let newSettings = JSON.parse(
fs.readFileSync(path.resolve('storage', 'settings.json'))
)
checkVersion(settingsInterface)
return newSettings
} catch (error) {
logger.error('Couldn´t read Settings.json file, creating af new', {})
saveSettings(settingsInterface)
Expand Down
22 changes: 22 additions & 0 deletions server/utils/migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ts-ignore
import { version } from '../../package.json'
import { ISettings } from '../reducers/settingsReducer'

export const checkVersion = (currentSettings: ISettings) => {
if (currentSettings.sisyfosVersion < version) {
migrateVersion(currentSettings)
}
}

export const getVersion = (): string => {
return version
}

const migrateVersion = (currentSettings: ISettings) => {
console.log(
'Migrating VERSION from',
currentSettings.sisyfosVersion,
' to ',
version
)
}
1 change: 1 addition & 0 deletions tsconfig-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Check for "any" while converting to TS this can be turned off.
"noImplicitAny": false,
"module": "commonjs",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
},
"include": ["src"]
Expand Down
53 changes: 24 additions & 29 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
{
"compilerOptions": {
// Target latest version of ECMAScript.
"target": "esnext",
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Process & infer types from .js files.
"allowJs": false,
// Don't emit; allow Babel to transform files.
"noEmit": false,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": false,
// Disallow features that require cross-file information for emit.
"isolatedModules": false,
// Import non-ES modules as default imports.
"esModuleInterop": true,
//Support for jsx.
"jsx": "react",
// Check for "any" while converting to TS this can be turned off.
"noImplicitAny": true,
"module": "commonjs",
"allowSyntheticDefaultImports": true
// Target latest version of ECMAScript.
"target": "esnext",
// Search under node_modules for non-relative imports.
"moduleResolution": "node",
// Process & infer types from .js files.
"allowJs": false,
// Don't emit; allow Babel to transform files.
"noEmit": false,
// Enable strictest settings like strictNullChecks & noImplicitAny.
"strict": false,
// Disallow features that require cross-file information for emit.
"isolatedModules": false,
// Import non-ES modules as default imports.
"esModuleInterop": true,
//Support for jsx.
"jsx": "react",
// Check for "any" while converting to TS this can be turned off.
"noImplicitAny": true,
"module": "commonjs",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
},
"include": [
"client", "server"
],
"exclude": [
"node_modules",
"**/node_modules/*",
"dist"
]
}
"include": ["client", "server"],
"exclude": ["node_modules", "**/node_modules/*", "dist"]
}
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/node@*", "@types/node@>=10.0.0":
"@types/node@*", "@types/node@>=10.0.0", "@types/node@^14.14.35":
version "14.14.35"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.35.tgz#42c953a4e2b18ab931f72477e7012172f4ffa313"
integrity sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==
Expand Down Expand Up @@ -4505,6 +4505,11 @@ jsesc@^2.5.1:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==

json-loader@^0.5.7:
version "0.5.7"
resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d"
integrity sha512-QLPs8Dj7lnf3e3QYS1zkCo+4ZwqOiF9d/nZnYozTISxXWCfNs9yuky5rJw4/W34s7POaNlbZmQGaB5NiXCbP4w==

json-parse-better-errors@^1.0.1, json-parse-better-errors@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
Expand Down

0 comments on commit 15e9b79

Please sign in to comment.