import { PerformanceData } from './src/types/orm/entities/PerformanceData';
import { PerformanceRecord } from './src/types/orm/entities/PerformanceRecord';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
+import { fileURLToPath } from 'url';
import path from 'path';
export default {
entities: [PerformanceRecord, PerformanceData],
type: 'sqlite',
clientUrl: `file://${path.join(
- path.resolve(__dirname),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url))),
`${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
)}`,
};
'uuid',
'ws',
'winston-daily-rotate-file',
- 'winston/lib/winston/transports',
+ 'winston/lib/winston/transports/index.js',
'winston',
'worker_threads',
],
import WorkerAbstract from '../worker/WorkerAbstract';
import WorkerFactory from '../worker/WorkerFactory';
import chalk from 'chalk';
+import { fileURLToPath } from 'url';
import { isMainThread } from 'worker_threads';
import path from 'path';
import { version } from '../../package.json';
private constructor() {
this.started = false;
this.workerScript = path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'charging-station',
'ChargingStationWorker.js'
);
const workerData: ChargingStationWorkerData = {
index,
templateFile: path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'assets',
'station-templates',
path.basename(stationTemplateUrl.file)
StopTransactionRequest,
StopTransactionResponse,
} from '../types/ocpp/Transaction';
+import { URL, fileURLToPath } from 'url';
import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
-import WebSocket, { Data, OPEN, RawData } from 'ws';
+import WebSocket, { Data, RawData } from 'ws';
import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
import { AutomaticTransactionGeneratorConfiguration } from '../types/AutomaticTransactionGenerator';
import { OCPPVersion } from '../types/ocpp/OCPPVersion';
import PerformanceStatistics from '../performance/PerformanceStatistics';
import { SupervisionUrlDistribution } from '../types/ConfigurationData';
-import { URL } from 'url';
import Utils from '../utils/Utils';
import crypto from 'crypto';
import fs from 'fs';
}
public isWebSocketConnectionOpened(): boolean {
- return this?.wsConnection?.readyState === OPEN;
+ return this?.wsConnection?.readyState === WebSocket.OPEN;
}
public getRegistrationStatus(): RegistrationStatus {
this.hashId = ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile());
logger.info(`${this.logPrefix()} Charging station hashId '${this.hashId}'`);
this.configurationFile = path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'assets',
'configurations',
this.hashId + '.json'
import { WebSocketCloseEventStatusString } from '../types/WebSocket';
import { WorkerProcessType } from '../types/Worker';
import crypto from 'crypto';
+import { fileURLToPath } from 'url';
import fs from 'fs';
import logger from '../utils/Logger';
import moment from 'moment';
return (
stationInfo.authorizationFile &&
path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'assets',
path.basename(stationInfo.authorizationFile)
)
OCPP16StandardParametersKey,
OCPP16SupportedFeatureProfiles,
} from '../../../types/ocpp/1.6/Configuration';
+import { URL, fileURLToPath } from 'url';
import type ChargingStation from '../../ChargingStation';
import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils';
import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
import OCPPError from '../../../exception/OCPPError';
import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
-import { URL } from 'url';
import Utils from '../../../utils/Utils';
import fs from 'fs';
import logger from '../../../utils/Logger';
let ftpClient: Client;
try {
const logFiles = fs
- .readdirSync(path.resolve(__dirname, '../../../../'))
+ .readdirSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'))
.filter((file) => file.endsWith('.log'))
.map((file) => path.join('./', file));
const diagnosticsArchive = chargingStation.stationInfo.chargingStationId + '_logs.tar.gz';
});
});
uploadResponse = await ftpClient.uploadFrom(
- path.join(path.resolve(__dirname, '../../../../'), diagnosticsArchive),
+ path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'),
+ diagnosticsArchive
+ ),
uri.pathname + diagnosticsArchive
);
if (uploadResponse.code === 226) {
import AbstractUIService from './ui-services/AbstractUIService';
import { Server as HttpServer } from 'http';
import { ProtocolVersion } from '../../types/UIProtocol';
-import { Server as WSServer } from 'ws';
+import WebSocket from 'ws';
export abstract class AbstractUIServer {
public readonly chargingStations: Set<string>;
protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>;
- protected server: WSServer | HttpServer;
+ protected server: WebSocket.Server | HttpServer;
public constructor() {
this.chargingStations = new Set<string>();
import { Protocol, ProtocolVersion } from '../../types/UIProtocol';
-import WebSocket, { OPEN, Server } from 'ws';
import { AbstractUIServer } from './AbstractUIServer';
import Configuration from '../../utils/Configuration';
import { ServerOptions } from '../../types/ConfigurationData';
import UIServiceFactory from './ui-services/UIServiceFactory';
import Utils from '../../utils/Utils';
+import WebSocket from 'ws';
import logger from '../../utils/Logger';
export default class UIWebSocketServer extends AbstractUIServer {
public constructor(options?: ServerOptions) {
super();
- this.server = new Server(options ?? Configuration.getUIServer().options);
+ this.server = new WebSocket.Server(options ?? Configuration.getUIServer().options);
}
public start(): void {
}
private broadcastToClients(message: string): void {
- for (const client of (this.server as Server).clients) {
- if (client?.readyState === OPEN) {
+ for (const client of (this.server as WebSocket.Server).clients) {
+ if (client?.readyState === WebSocket.OPEN) {
client.send(message);
}
}
import WorkerConstants from '../worker/WorkerConstants';
import { WorkerProcessType } from '../types/Worker';
import chalk from 'chalk';
+import { fileURLToPath } from 'url';
import fs from 'fs';
import path from 'path';
export default class Configuration {
private static configurationFile = path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'assets',
'config.json'
);
switch (storageType) {
case StorageType.JSON_FILE:
return `file://${path.join(
- path.resolve(__dirname, '../../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME
)}`;
case StorageType.SQLITE:
- return `file://${path.join(path.resolve(__dirname, '../../'), SQLiteFileName)}`;
+ return `file://${path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+ SQLiteFileName
+ )}`;
default:
throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
}
-import { Console, File } from 'winston/lib/winston/transports';
import { Logger, createLogger, format, transport } from 'winston';
import Configuration from './Configuration';
import DailyRotateFile from 'winston-daily-rotate-file';
import { Format } from 'logform';
+import TransportType from 'winston/lib/winston/transports/index.js';
import Utils from './Utils';
let transports: transport[];
];
} else {
transports = [
- new File({ filename: Configuration.getLogErrorFile(), level: 'error' }),
- new File({ filename: Configuration.getLogFile() }),
+ new TransportType.File({ filename: Configuration.getLogErrorFile(), level: 'error' }),
+ new TransportType.File({ filename: Configuration.getLogFile() }),
];
}
//
if (Configuration.getLogConsole()) {
logger.add(
- new Console({
+ new TransportType.Console({
format: format.combine(
format.splat(),
(format[Configuration.getLogFormat()] as () => Format)()