// Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved.
import { EventEmitter } from 'node:events'
-import { dirname, extname, join, parse } from 'node:path'
+import { dirname, extname, join } from 'node:path'
import process, { exit } from 'node:process'
import { fileURLToPath } from 'node:url'
import { isMainThread } from 'node:worker_threads'
import {
Configuration,
Constants,
+ buildTemplateName,
buildTemplateStatisticsPayload,
formatDurationMilliSeconds,
generateUUID,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) {
try {
- const nbStations =
- this.templateStatistics.get(parse(stationTemplateUrl.file).name)?.configured ??
- stationTemplateUrl.numberOfStations
+ const nbStations = stationTemplateUrl.numberOfStations
for (let index = 1; index <= nbStations; index++) {
await this.addChargingStation(index, stationTemplateUrl.file)
}
const stationTemplateUrls = Configuration.getStationTemplateUrls()!
if (isNotEmptyArray(stationTemplateUrls)) {
for (const stationTemplateUrl of stationTemplateUrls) {
- const templateName = join(
- parse(stationTemplateUrl.file).dir,
- parse(stationTemplateUrl.file).name
- )
+ const templateName = buildTemplateName(stationTemplateUrl.file)
this.templateStatistics.set(templateName, {
configured: stationTemplateUrl.numberOfStations,
added: 0,
public async addChargingStation (
index: number,
- stationTemplateFile: string,
+ templateFile: string,
options?: ChargingStationOptions
): Promise<void> {
await this.workerImplementation?.addElement({
dirname(fileURLToPath(import.meta.url)),
'assets',
'station-templates',
- stationTemplateFile
+ templateFile
),
options
})
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const templateStatistics = this.templateStatistics.get(parse(stationTemplateFile).name)!
+ const templateStatistics = this.templateStatistics.get(buildTemplateName(templateFile))!
++templateStatistics.added
templateStatistics.indexes.add(index)
}
import { createHash } from 'node:crypto'
import { EventEmitter } from 'node:events'
import { type FSWatcher, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
-import { dirname, join, parse } from 'node:path'
+import { dirname, join } from 'node:path'
import { URL } from 'node:url'
import { parentPort } from 'node:worker_threads'
buildEvsesStatus,
buildStartedMessage,
buildStoppedMessage,
+ buildTemplateName,
buildUpdatedMessage,
clone,
convertToBoolean,
const stationInfo = stationTemplateToStationInfo(stationTemplate)
stationInfo.hashId = getHashId(this.index, stationTemplate)
stationInfo.templateIndex = this.index
- stationInfo.templateName = parse(this.templateFile).name
+ stationInfo.templateName = buildTemplateName(this.templateFile)
stationInfo.chargingStationId = getChargingStationId(this.index, stationTemplate)
createSerialNumber(stationTemplate, stationInfo)
stationInfo.voltageOut = this.getVoltageOut(stationInfo)
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (stationInfo.templateName == null) {
- stationInfo.templateName = parse(this.templateFile).name
+ stationInfo.templateName = buildTemplateName(this.templateFile)
}
}
}
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,
)
}
+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)
}
} from './MessageChannelUtils.js'
export {
JSONStringifyWithMapSupport,
+ buildTemplateName,
clone,
convertToBoolean,
convertToDate,