diff --git a/package.json b/package.json index da310d75..455a80e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@brewskey/spark-server", - "version": "1.0.5", + "version": "1.0.6", "license": "AGPL-3.0", "repository": { "type": "git", diff --git a/packages/spark-protocol/package.json b/packages/spark-protocol/package.json index ad357aac..ccba45e2 100644 --- a/packages/spark-protocol/package.json +++ b/packages/spark-protocol/package.json @@ -1,6 +1,6 @@ { "name": "@brewskey/spark-protocol", - "version": "1.0.5", + "version": "1.0.6", "main": "./dist/index.js", "repository": { "type": "git", diff --git a/packages/spark-protocol/src/__tests__/FirmwareManager.test.ts b/packages/spark-protocol/src/__tests__/FirmwareManager.test.ts index a5650946..c1452e44 100644 --- a/packages/spark-protocol/src/__tests__/FirmwareManager.test.ts +++ b/packages/spark-protocol/src/__tests__/FirmwareManager.test.ts @@ -1,7 +1,12 @@ +import SETTINGS from '../settings'; import FirmwareManager from '../lib/FirmwareManager'; import { SystemInformation } from 'binary-version-reader'; describe('FirmwareManager', () => { + beforeAll(() => { + FirmwareManager.initialize(SETTINGS.BINARIES_DIRECTORY); + }); + test('should subscribe to event', async () => { const SYSTEM: SystemInformation = { f: [], diff --git a/packages/spark-protocol/src/defaultBindings.ts b/packages/spark-protocol/src/defaultBindings.ts index 77fa8ff1..d0d358b6 100644 --- a/packages/spark-protocol/src/defaultBindings.ts +++ b/packages/spark-protocol/src/defaultBindings.ts @@ -11,6 +11,7 @@ import MockProductDeviceRepository from './repository/MockProductDeviceRepositor import MockProductFirmwareRepository from './repository/MockProductFirmwareRepository'; import ServerKeyFileRepository from './repository/ServerKeyFileRepository'; import protocolSettings from './settings'; +import FirmwareManager from './lib/FirmwareManager'; type ServerSettings = { BINARIES_DIRECTORY?: string; @@ -31,6 +32,7 @@ const defaultBindings = ( serverSettings: ServerSettings, ) => { const mergedSettings = { ...protocolSettings, ...serverSettings } as const; + FirmwareManager.initialize(mergedSettings.BINARIES_DIRECTORY); // Settings container.bindValue('DEVICE_DIRECTORY', mergedSettings.DEVICE_DIRECTORY); diff --git a/packages/spark-protocol/src/lib/FirmwareManager.ts b/packages/spark-protocol/src/lib/FirmwareManager.ts index 8c397c89..35bfa83a 100644 --- a/packages/spark-protocol/src/lib/FirmwareManager.ts +++ b/packages/spark-protocol/src/lib/FirmwareManager.ts @@ -16,14 +16,6 @@ import Logger from './logger'; const logger = Logger.createModuleLogger(module); import { filterFalsyValues } from '../filterFalsyValues'; -// eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires -const FirmwareSettings = require( - path.join( - protocolSettings.BINARIES_DIRECTORY, - '../third-party/settings.json', - ), -) as FirmwareSetting[]; - const NUMBER_BY_FUNCTION = { b: 2, s: 4, @@ -42,7 +34,15 @@ export type OTAUpdate = { allUpdateFiles: Array; }; +let FirmwareSettings: FirmwareSetting[] = []; class FirmwareManager { + static initialize(binariesDirectory: string): void { + // eslint-disable-next-line import/no-dynamic-require, @typescript-eslint/no-var-requires + FirmwareSettings = require( + path.join(binariesDirectory, '../third-party/settings.json'), + ) as FirmwareSetting[]; + } + static async getMissingModules( systemInformation: SystemInformation, ): Promise {