Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createFilePath(filePath: string) {
// ###TODO: Make this function platform independent
const files = filePath.split(/\/|\\/); // /\.[^/.]+$/ // /\/[^\/]+$/
let curFile = "";
for (const file of files) {
if (file === "") break;
curFile += file + "\\";
if (!IModelJsFs.existsSync(curFile)) IModelJsFs.mkdirSync(curFile);
}
}
export function createNewCsvFile(filePath: string, fileName: string, data: Map): boolean {
const file = path.join(filePath, fileName);
if (!IModelJsFs.existsSync(filePath)) createFilePath(filePath);
if (!IModelJsFs.existsSync(file)) {
try {
let colNames = "";
data.forEach((_value, colName) => {
colNames += colName + ",";
});
colNames += "\r\n";
IModelJsFs.writeFileSync(file, colNames);
} catch (err) {
/* Handle the error */
}
return true;
} else {
return false;
}
}
export function createNewCsvFile(filePath: string, fileName: string, data: Map): boolean {
const file = path.join(filePath, fileName);
if (!IModelJsFs.existsSync(filePath)) createFilePath(filePath);
if (!IModelJsFs.existsSync(file)) {
try {
let colNames = "";
data.forEach((_value, colName) => {
colNames += colName + ",";
});
colNames += "\r\n";
IModelJsFs.writeFileSync(file, colNames);
} catch (err) {
/* Handle the error */
}
return true;
} else {
return false;
}
}
public async getDefaultConfigs(): Promise {
let jsonStr = "";
let defaultJsonFile;
if (MobileRpcConfiguration.isMobileBackend && process.env.DOCS) {
defaultJsonFile = path.join(process.env.DOCS, "MobilePerformanceConfig.json");
} else {
defaultJsonFile = "./src/backend/DefaultConfig.json";
}
if (IModelJsFs.existsSync(DisplayPerfRpcInterface.jsonFilePath)) {
jsonStr = IModelJsFs.readFileSync(DisplayPerfRpcInterface.jsonFilePath).toString();
} else if (IModelJsFs.existsSync(defaultJsonFile)) {
jsonStr = IModelJsFs.readFileSync(defaultJsonFile).toString();
}
let argOutputPath: string | undefined;
process.argv.forEach((arg, index) => {
if (index >= 2 && arg !== "chrome" && arg !== "edge" && arg !== "firefox" && arg.split(".").pop() !== "json") {
while (arg.endsWith("\\") || arg.endsWith("\/"))
arg = arg.slice(0, -1);
argOutputPath = "\"argOutputPath\": \"" + arg + "\",";
}
});
if (argOutputPath) {
const firstBraceIndex = jsonStr.indexOf("{") + 1;
jsonStr = jsonStr.slice(0, firstBraceIndex) + argOutputPath + jsonStr.slice(firstBraceIndex);
public async savePng(fileName: string, png: string) {
let filePath;
if (MobileRpcConfiguration.isMobileBackend && process.env.DOCS) {
filePath = process.env.DOCS;
fileName = path.join(filePath, fileName);
} else {
filePath = this.getFilePath(fileName);
}
if (!IModelJsFs.existsSync(filePath)) createFilePath(filePath);
if (IModelJsFs.existsSync(fileName)) IModelJsFs.unlinkSync(fileName);
const buf = Buffer.from(png, "base64");
IModelJsFs.writeFileSync(fileName, buf);
}
public async readExternalSavedViews(bimfileName: string): Promise {
const esvFileName = this.createEsvFilename(bimfileName);
if (!IModelJsFs.existsSync(esvFileName)) {
return "";
}
const jsonStr = IModelJsFs.readFileSync(esvFileName).toString();
if (undefined === jsonStr)
return "";
return jsonStr;
}
public async saveReport(): Promise {
const pth = "./lib/outputdir";
if (!IModelJsFs.existsSync(pth))
IModelJsFs.mkdirSync(pth);
const csvPath = path.join(pth, "IntegrationPefTests.csv");
TestRpcImpl.reporter.exportCSV(csvPath);
}
public async savePng(fileName: string, png: string) {
let filePath;
if (MobileRpcConfiguration.isMobileBackend && process.env.DOCS) {
filePath = process.env.DOCS;
fileName = path.join(filePath, fileName);
} else {
filePath = this.getFilePath(fileName);
}
if (!IModelJsFs.existsSync(filePath)) createFilePath(filePath);
if (IModelJsFs.existsSync(fileName)) IModelJsFs.unlinkSync(fileName);
const buf = Buffer.from(png, "base64");
IModelJsFs.writeFileSync(fileName, buf);
}
public async saveCsv(outputPath: string, outputName: string, rowDataJson: string, csvFormat?: string): Promise {
const rowData = new Map(JSON.parse(rowDataJson)) as Map;
const testName = rowData.get("Test Name") as string;
rowData.delete("Test Name");
if (csvFormat === "original") {
rowData.delete("Browser");
if (outputPath !== undefined && outputName !== undefined) {
if (MobileRpcConfiguration.isMobileBackend && process.env.DOCS)
outputPath = process.env.DOCS;
let outputFile = this.createFullFilePath(outputPath, outputName);
outputFile = outputFile ? outputFile : "";
if (IModelJsFs.existsSync(outputFile)) {
addColumnsToCsvFile(outputFile, rowData);
} else {
createNewCsvFile(outputPath, outputName, rowData);
}
addDataToCsvFile(outputFile, rowData);
}
} else {
const rowObject = this.mapToObj(rowData);
if (process.env.browser) {
rowObject.browser = process.env.browser;
}
const totalTime = rowObject["Total Time"] as number;
const fps = rowObject["Effective FPS"] as number;
this._reporter.addEntry("DisplayTests", testName, "Total time", totalTime, rowObject);
this._reporter.addEntry("DisplayTests", testName, "Effective FPS", fps, rowObject);
}