From: Jérôme Benoit Date: Wed, 6 Mar 2024 12:50:39 +0000 (+0100) Subject: refactor: move charging station helper to its right place X-Git-Tag: v1.3.0~43 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ffb833ec8daea8112feed14af15cdfdb67f9d41b;p=e-mobility-charging-stations-simulator.git refactor: move charging station helper to its right place Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index bd7fda2d..0c1eeeec 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -10,7 +10,7 @@ import type { Worker } from 'worker_threads' import chalk from 'chalk' import { type MessageHandler, availableParallelism } from 'poolifier' -import { waitChargingStationEvents } from './Helpers.js' +import { buildTemplateName, waitChargingStationEvents } from './Helpers.js' import type { AbstractUIServer } from './ui-server/AbstractUIServer.js' import { UIServerFactory } from './ui-server/UIServerFactory.js' import { version } from '../../package.json' @@ -36,7 +36,6 @@ import { import { Configuration, Constants, - buildTemplateName, buildTemplateStatisticsPayload, formatDurationMilliSeconds, generateUUID, diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index f79a59ce..5a724e53 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -21,6 +21,7 @@ import { } from './ConfigurationKeyUtils.js' import { buildConnectorsMap, + buildTemplateName, checkChargingStation, checkConfiguration, checkConnectorsConfiguration, @@ -131,7 +132,6 @@ import { buildEvsesStatus, buildStartedMessage, buildStoppedMessage, - buildTemplateName, buildUpdatedMessage, clone, convertToBoolean, diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 22ed5041..9c790268 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -1,6 +1,6 @@ import { createHash, randomBytes } from 'node:crypto' import type { EventEmitter } from 'node:events' -import { basename, dirname, join } from 'node:path' +import { basename, dirname, isAbsolute, join, parse, relative, resolve } from 'node:path' import { env } from 'node:process' import { fileURLToPath } from 'node:url' @@ -73,6 +73,17 @@ import { const moduleName = 'Helpers' +export const buildTemplateName = (templateFile: string): string => { + if (isAbsolute(templateFile)) { + templateFile = relative( + resolve(join(dirname(fileURLToPath(import.meta.url)), 'assets', 'station-templates')), + templateFile + ) + } + const templateFileParsedPath = parse(templateFile) + return join(templateFileParsedPath.dir, templateFileParsedPath.name) +} + export const getChargingStationId = ( index: number, stationTemplate: ChargingStationTemplate | undefined diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index c39c95e6..abfac5e4 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -1,7 +1,5 @@ import { getRandomValues, randomBytes, randomInt, randomUUID } from 'node:crypto' -import { dirname, isAbsolute, join, parse, relative, resolve } from 'node:path' import { env, nextTick } from 'node:process' -import { fileURLToPath } from 'node:url' import { formatDuration, @@ -209,17 +207,6 @@ export const getRandomFloatFluctuatedRounded = ( ) } -export const buildTemplateName = (templateFile: string): string => { - if (isAbsolute(templateFile)) { - templateFile = relative( - resolve(join(dirname(fileURLToPath(import.meta.url)), 'assets', 'station-templates')), - templateFile - ) - } - const templateFileParsedPath = parse(templateFile) - return join(templateFileParsedPath.dir, templateFileParsedPath.name) -} - export const extractTimeSeriesValues = (timeSeries: TimestampedData[]): number[] => { return timeSeries.map(timeSeriesItem => timeSeriesItem.value) } diff --git a/src/utils/index.ts b/src/utils/index.ts index fdcb6fa2..1bc4fe7e 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -29,7 +29,6 @@ export { } from './MessageChannelUtils.js' export { JSONStringifyWithMapSupport, - buildTemplateName, clone, convertToBoolean, convertToDate,