Removes trailing spaces.

This commit is contained in:
Refringe 2023-11-07 23:29:25 -05:00
parent a190311612
commit eaa4c3cf0b
No known key found for this signature in database
GPG Key ID: 64E03E5F892C6F9E
4 changed files with 95 additions and 96 deletions

View File

@ -10,7 +10,7 @@ import lockfile from "proper-lockfile";
import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
@injectable()
export class VFS
export class VFS
{
accessFilePromisify: (path: fs.PathLike, mode?: number) => Promise<void>;
copyFilePromisify: (src: fs.PathLike, dst: fs.PathLike, flags?: number) => Promise<void>;
@ -39,14 +39,14 @@ export class VFS
this.renamePromisify = promisify(fs.renameSync);
}
public exists(filepath: fs.PathLike): boolean
public exists(filepath: fs.PathLike): boolean
{
return fs.existsSync(filepath);
}
public async existsAsync(filepath: fs.PathLike): Promise<boolean>
public async existsAsync(filepath: fs.PathLike): Promise<boolean>
{
try
try
{
// Create the command to add to the queue
const command = {
@ -59,19 +59,19 @@ export class VFS
// If no Exception, the file exists
return true;
}
catch
catch
{
// If Exception, the file does not exis
// If Exception, the file does not exist
return false;
}
}
public copyFile(filepath: fs.PathLike, target: fs.PathLike): void
public copyFile(filepath: fs.PathLike, target: fs.PathLike): void
{
fs.copyFileSync(filepath, target);
}
public async copyAsync(filepath: fs.PathLike, target: fs.PathLike): Promise<void>
public async copyAsync(filepath: fs.PathLike, target: fs.PathLike): Promise<void>
{
const command = {
uuid: crypto.randomUUID(),
@ -80,12 +80,12 @@ export class VFS
await this.asyncQueue.waitFor(command);
}
public createDir(filepath: string): void
public createDir(filepath: string): void
{
fs.mkdirSync(filepath.substr(0, filepath.lastIndexOf("/")), { "recursive": true });
}
public async createDirAsync(filepath: string): Promise<void>
public async createDirAsync(filepath: string): Promise<void>
{
const command = {
uuid: crypto.randomUUID(),
@ -94,65 +94,65 @@ export class VFS
await this.asyncQueue.waitFor(command);
}
public copyDir(filepath: string, target: string, fileExtensions: string | string[] = undefined): void
public copyDir(filepath: string, target: string, fileExtensions: string | string[] = undefined): void
{
const files = this.getFiles(filepath);
const dirs = this.getDirs(filepath);
if (!this.exists(target))
if (!this.exists(target))
{
this.createDir(`${target}/`);
}
for (const dir of dirs)
for (const dir of dirs)
{
this.copyDir(path.join(filepath, dir), path.join(target, dir), fileExtensions);
}
for (const file of files)
for (const file of files)
{
// copy all if fileExtension is not set, copy only those with fileExtension if set
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
{
this.copyFile(path.join(filepath, file), path.join(target, file));
}
}
}
public async copyDirAsync(filepath: string, target: string, fileExtensions: string | string[]): Promise<void>
public async copyDirAsync(filepath: string, target: string, fileExtensions: string | string[]): Promise<void>
{
const files = this.getFiles(filepath);
const dirs = this.getDirs(filepath);
if (!await this.existsAsync(target))
if (!await this.existsAsync(target))
{
await this.createDirAsync(`${target}/`);
}
for (const dir of dirs)
for (const dir of dirs)
{
await this.copyDirAsync(path.join(filepath, dir), path.join(target, dir), fileExtensions);
}
for (const file of files)
for (const file of files)
{
// copy all if fileExtension is not set, copy only those with fileExtension if set
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
if (!fileExtensions || fileExtensions.includes(file.split(".").pop()))
{
await this.copyAsync(path.join(filepath, file), path.join(target, file));
}
}
}
public readFile(...args: Parameters<typeof fs.readFileSync>): string
public readFile(...args: Parameters<typeof fs.readFileSync>): string
{
const read = fs.readFileSync(...args);
if (this.isBuffer(read))
return read.toString();
return read;
}
public async readFileAsync(path: fs.PathLike): Promise<string>
public async readFileAsync(path: fs.PathLike): Promise<string>
{
const read = await this.readFilePromisify(path);
if (this.isBuffer(read))
@ -165,11 +165,11 @@ export class VFS
return value?.write && value.toString && value.toJSON && value.equals;
}
public writeFile(filepath: any, data = "", append = false, atomic = true): void
public writeFile(filepath: any, data = "", append = false, atomic = true): void
{
const options = (append) ? { "flag": "a" } : { "flag": "w" };
if (!this.exists(filepath))
if (!this.exists(filepath))
{
this.createDir(filepath);
fs.writeFileSync(filepath, "");
@ -177,53 +177,53 @@ export class VFS
this.lockFileSync(filepath);
if (!append && atomic)
if (!append && atomic)
{
writeFileSync(filepath, data);
}
else
else
{
fs.writeFileSync(filepath, data, options);
}
if (this.checkFileSync(filepath))
if (this.checkFileSync(filepath))
{
this.unlockFileSync(filepath);
}
}
public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void>
public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void>
{
const options = (append) ? { "flag": "a" } : { "flag": "w" };
if (!await this.exists(filepath))
if (!await this.exists(filepath))
{
await this.createDir(filepath);
await this.writeFilePromisify(filepath, "");
}
if (!append && atomic)
if (!append && atomic)
{
await this.writeFilePromisify(filepath, data);
}
else
else
{
await this.writeFilePromisify(filepath, data, options);
}
}
public getFiles(filepath: string): string[]
public getFiles(filepath: string): string[]
{
return fs.readdirSync(filepath).filter((item) =>
return fs.readdirSync(filepath).filter((item) =>
{
return fs.statSync(path.join(filepath, item)).isFile();
});
}
public async getFilesAsync(filepath: string): Promise<string[]>
public async getFilesAsync(filepath: string): Promise<string[]>
{
const addr = await this.readdirPromisify(filepath);
return addr.filter(async (item) =>
return addr.filter(async (item) =>
{
const stat = await this.statPromisify(path.join(filepath, item));
return stat.isFile();
@ -231,45 +231,45 @@ export class VFS
}
public getDirs(filepath: string): string[]
public getDirs(filepath: string): string[]
{
return fs.readdirSync(filepath).filter((item) =>
return fs.readdirSync(filepath).filter((item) =>
{
return fs.statSync(path.join(filepath, item)).isDirectory();
});
}
public async getDirsAsync(filepath: string): Promise<string[]>
public async getDirsAsync(filepath: string): Promise<string[]>
{
const addr = await this.readdirPromisify(filepath);
return addr.filter(async (item) =>
return addr.filter(async (item) =>
{
const stat = await this.statPromisify(path.join(filepath, item));
return stat.isDirectory();
});
}
public removeFile(filepath: string): void
public removeFile(filepath: string): void
{
fs.unlinkSync(filepath);
}
public async removeFileAsync(filepath: string): Promise<void>
public async removeFileAsync(filepath: string): Promise<void>
{
await this.unlinkPromisify(filepath);
}
public removeDir(filepath: string): void
public removeDir(filepath: string): void
{
const files = this.getFiles(filepath);
const dirs = this.getDirs(filepath);
for (const dir of dirs)
for (const dir of dirs)
{
this.removeDir(path.join(filepath, dir));
}
for (const file of files)
for (const file of files)
{
this.removeFile(path.join(filepath, file));
}
@ -277,19 +277,19 @@ export class VFS
fs.rmdirSync(filepath);
}
public async removeDirAsync(filepath: string): Promise<void>
public async removeDirAsync(filepath: string): Promise<void>
{
const files = this.getFiles(filepath);
const dirs = this.getDirs(filepath);
const promises = [];
for (const dir of dirs)
for (const dir of dirs)
{
promises.push(this.removeDirAsync(path.join(filepath, dir)));
}
for (const file of files)
for (const file of files)
{
promises.push(this.removeFile(path.join(filepath, file)));
}
@ -298,45 +298,45 @@ export class VFS
await this.rmdirPromisify(filepath);
}
public rename(oldPath: string, newPath: string): void
public rename(oldPath: string, newPath: string): void
{
fs.renameSync(oldPath, newPath);
}
public async renameAsync(oldPath: string, newPath: string): Promise<void>
public async renameAsync(oldPath: string, newPath: string): Promise<void>
{
await this.renamePromisify(oldPath, newPath);
}
protected lockFileSync(filepath: any): void
protected lockFileSync(filepath: any): void
{
lockfile.lockSync(filepath);
}
protected checkFileSync(filepath: any): any
protected checkFileSync(filepath: any): any
{
return lockfile.checkSync(filepath);
}
protected unlockFileSync(filepath: any): void
protected unlockFileSync(filepath: any): void
{
lockfile.unlockSync(filepath);
}
public getFileExtension(filepath: string): string
public getFileExtension(filepath: string): string
{
return filepath.split(".").pop();
}
public stripExtension(filepath: string): string
public stripExtension(filepath: string): string
{
return filepath.split(".").slice(0, -1).join(".");
}
public async minifyAllJsonInDirRecursive(filepath: string): Promise<void>
public async minifyAllJsonInDirRecursive(filepath: string): Promise<void>
{
const files = this.getFiles(filepath).filter((item) => this.getFileExtension(item) === "json");
for (const file of files)
for (const file of files)
{
const filePathAndName = path.join(filepath, file);
const minified = JSON.stringify(JSON.parse(this.readFile(filePathAndName)));
@ -344,16 +344,16 @@ export class VFS
}
const dirs = this.getDirs(filepath);
for (const dir of dirs)
for (const dir of dirs)
{
this.minifyAllJsonInDirRecursive(path.join(filepath, dir));
}
}
public async minifyAllJsonInDirRecursiveAsync(filepath: string): Promise<void>
public async minifyAllJsonInDirRecursiveAsync(filepath: string): Promise<void>
{
const files = this.getFiles(filepath).filter((item) => this.getFileExtension(item) === "json");
for (const file of files)
for (const file of files)
{
const filePathAndName = path.join(filepath, file);
const minified = JSON.stringify(JSON.parse(await this.readFile(filePathAndName)));
@ -362,7 +362,7 @@ export class VFS
const dirs = this.getDirs(filepath);
const promises: Promise<void>[] = [];
for (const dir of dirs)
for (const dir of dirs)
{
promises.push(this.minifyAllJsonInDirRecursive(path.join(filepath, dir)));
}

View File

@ -12,7 +12,7 @@ import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
import { ICommand } from "@spt-aki/models/spt/utils/ICommand";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
export abstract class AbstractWinstonLogger implements ILogger
export abstract class AbstractWinstonLogger implements ILogger
{
protected showDebugInConsole = false;
protected filePath: string;
@ -55,7 +55,7 @@ export abstract class AbstractWinstonLogger implements ILogger
this.filePath = `${this.getFilePath()}${this.getFileName()}`;
this.writeFilePromisify = promisify(fs.writeFile);
this.showDebugInConsole = globalThis.G_DEBUG_CONFIGURATION;
if (!fs.existsSync(this.getFilePath()))
if (!fs.existsSync(this.getFilePath()))
{
fs.mkdirSync(this.getFilePath(), { recursive: true });
}
@ -69,7 +69,7 @@ export abstract class AbstractWinstonLogger implements ILogger
level: this.showDebugInConsole ? "debug" : "custom",
format: format.combine(
format.colorize({ all: true, colors: this.logLevels.colors }),
format.printf(({ message }) =>
format.printf(({ message }) =>
{
return `${message}`;
})
@ -91,7 +91,7 @@ export abstract class AbstractWinstonLogger implements ILogger
format.timestamp(),
format.align(),
format.json(),
format.printf(({ timestamp, level, message }) =>
format.printf(({ timestamp, level, message }) =>
{
return `[${timestamp}] ${level}: ${message}`;
})
@ -108,7 +108,7 @@ export abstract class AbstractWinstonLogger implements ILogger
if (this.isLogExceptions())
{
process.on("uncaughtException", (error) =>
process.on("uncaughtException", (error) =>
{
this.error(`${error.name}: ${error.message}`);
this.error(error.stack);
@ -123,9 +123,9 @@ export abstract class AbstractWinstonLogger implements ILogger
protected abstract isLogExceptions(): boolean;
protected abstract getFilePath(): string;
protected abstract getFileName(): string;
protected getLogMaxSize(): string
{
return "5m";
@ -136,7 +136,7 @@ export abstract class AbstractWinstonLogger implements ILogger
return "14d";
}
public async writeToLogFile(data: string | Daum): Promise<void>
public async writeToLogFile(data: string | Daum): Promise<void>
{
const command: ICommand = {
uuid: crypto.randomUUID(),
@ -145,7 +145,7 @@ export abstract class AbstractWinstonLogger implements ILogger
await this.asyncQueue.waitFor(command);
}
public async log(data: string | Error | Record<string, unknown>, color: string, backgroundColor = "" ): Promise<void>
public async log(data: string | Error | Record<string, unknown>, color: string, backgroundColor = "" ): Promise<void>
{
const textColor = `${color} ${backgroundColor}`.trimEnd();
const tmpLogger = createLogger({
@ -161,14 +161,14 @@ export abstract class AbstractWinstonLogger implements ILogger
let command: ICommand;
if (typeof (data) === "string")
if (typeof (data) === "string")
{
command = {
uuid: crypto.randomUUID(),
cmd: async () => await tmpLogger.log("custom", data)
};
}
else
else
{
command = {
uuid: crypto.randomUUID(),
@ -179,7 +179,7 @@ export abstract class AbstractWinstonLogger implements ILogger
await this.asyncQueue.waitFor(command);
}
public async error(data: string | Record<string, unknown>): Promise<void>
public async error(data: string | Record<string, unknown>): Promise<void>
{
const command: ICommand = {
uuid: crypto.randomUUID(),
@ -188,7 +188,7 @@ export abstract class AbstractWinstonLogger implements ILogger
await this.asyncQueue.waitFor(command);
}
public async warning(data: string | Record<string, unknown>): Promise<void>
public async warning(data: string | Record<string, unknown>): Promise<void>
{
const command: ICommand = {
uuid: crypto.randomUUID(),
@ -197,7 +197,7 @@ export abstract class AbstractWinstonLogger implements ILogger
await this.asyncQueue.waitFor(command);
}
public async success(data: string | Record<string, unknown>): Promise<void>
public async success(data: string | Record<string, unknown>): Promise<void>
{
const command: ICommand = {
uuid: crypto.randomUUID(),
@ -206,7 +206,7 @@ export abstract class AbstractWinstonLogger implements ILogger
await this.asyncQueue.waitFor(command);
}
public async info(data: string | Record<string, unknown>): Promise<void>
public async info(data: string | Record<string, unknown>): Promise<void>
{
const command: ICommand = {
uuid: crypto.randomUUID(),
@ -231,18 +231,18 @@ export abstract class AbstractWinstonLogger implements ILogger
await this.asyncQueue.waitFor(command);
}
public async debug(data: string | Record<string, unknown>, onlyShowInConsole = false): Promise<void>
public async debug(data: string | Record<string, unknown>, onlyShowInConsole = false): Promise<void>
{
let command: ICommand;
if (onlyShowInConsole)
if (onlyShowInConsole)
{
command = {
uuid: crypto.randomUUID(),
cmd: async () => await this.log(data, this.logLevels.colors.debug)
};
}
else
else
{
command = {
uuid: crypto.randomUUID(),

View File

@ -4,9 +4,8 @@ import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
import { AbstractWinstonLogger } from "@spt-aki/utils/logging/AbstractWinstonLogger";
@injectable()
export class WinstonMainLogger extends AbstractWinstonLogger
export class WinstonMainLogger extends AbstractWinstonLogger
{
constructor(
@inject("AsyncQueue") protected asyncQueue: IAsyncQueue
)
@ -14,27 +13,27 @@ export class WinstonMainLogger extends AbstractWinstonLogger
super(asyncQueue);
}
protected isLogExceptions(): boolean
protected isLogExceptions(): boolean
{
return true;
}
protected isLogToFile(): boolean
{
return true;
}
protected isLogToConsole(): boolean
protected isLogToFile(): boolean
{
return true;
}
protected getFilePath(): string
protected isLogToConsole(): boolean
{
return true;
}
protected getFilePath(): string
{
return "./user/logs/";
}
protected getFileName(): string
protected getFileName(): string
{
return "server-%DATE%.log";
}

View File

@ -4,7 +4,7 @@ import { IAsyncQueue } from "@spt-aki/models/spt/utils/IAsyncQueue";
import { AbstractWinstonLogger } from "@spt-aki/utils/logging/AbstractWinstonLogger";
@injectable()
export class WinstonRequestLogger extends AbstractWinstonLogger
export class WinstonRequestLogger extends AbstractWinstonLogger
{
constructor(
@inject("AsyncQueue") protected asyncQueue: IAsyncQueue
@ -13,27 +13,27 @@ export class WinstonRequestLogger extends AbstractWinstonLogger
super(asyncQueue);
}
protected isLogExceptions(): boolean
protected isLogExceptions(): boolean
{
return false;
}
protected isLogToFile(): boolean
protected isLogToFile(): boolean
{
return true;
}
protected isLogToConsole(): boolean
protected isLogToConsole(): boolean
{
return false;
}
protected getFilePath(): string
protected getFilePath(): string
{
return "./user/logs/requests/";
}
protected getFileName(): string
protected getFileName(): string
{
return "requests-%DATE%.log";
}