From a132eca20e6c96f0e57ea70b3e97851cc66afb9f Mon Sep 17 00:00:00 2001 From: Shailesh Pachbhai Date: Wed, 25 Sep 2024 00:49:35 +0530 Subject: [PATCH] feat: filter the definition files --- src/migration/related/LwcMigration.ts | 32 ++++++++++++------- src/utils/lwcparser/fileutils/FileDiffUtil.ts | 7 +--- .../jsParser/JavaScriptFileParser.ts | 5 --- .../lwcparser/jsParser/JavaScriptParser.ts | 3 ++ src/utils/lwcparser/xmlParser/XmlParser.ts | 5 +-- .../resultsbuilder/assessmentReporter.ts | 4 +-- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/migration/related/LwcMigration.ts b/src/migration/related/LwcMigration.ts index ad0c1fa..9dd18a6 100644 --- a/src/migration/related/LwcMigration.ts +++ b/src/migration/related/LwcMigration.ts @@ -25,7 +25,7 @@ export class LwcMigration extends BaseRelatedObjectMigration { const type = 'assessment'; const pwd = shell.pwd(); shell.cd(this.projectPath); - sfProject.retrieve(LWCTYPE, this.org.getUsername()); + // sfProject.retrieve(LWCTYPE, this.org.getUsername()); const filesMap = this.processLwcFiles(this.projectPath); shell.cd(pwd); return this.processFiles(filesMap, type); @@ -61,17 +61,21 @@ export class LwcMigration extends BaseRelatedObjectMigration { const changeInfos: FileChangeInfo[] = []; if (dir !== 'lwc') { for (const file of fileList) { - const processor = FileProcessorFactory.getFileProcessor(file.ext); - if (processor != null) { - const path = file.location; - const name = file.name; - const diff = processor.process(file, type, this.namespace); - const fileInfo: FileChangeInfo = { - path, - name, - diff, - }; - changeInfos.push(fileInfo); + if (this.isValideFile(file.name)) { + const processor = FileProcessorFactory.getFileProcessor(file.ext); + if (processor != null) { + const path = file.location; + const name = file.name + file.ext; + const diff = processor.process(file, type, this.namespace); + if (diff != null) { + const fileInfo: FileChangeInfo = { + path, + name, + diff, + }; + changeInfos.push(fileInfo); + } + } } } const name = dir; @@ -89,4 +93,8 @@ export class LwcMigration extends BaseRelatedObjectMigration { Logger.logger.error(error.message); } } + + private isValideFile(filename: string): boolean { + return !filename.includes('_def') && !filename.includes('styleDefinition') && !filename.includes('definition'); + } } diff --git a/src/utils/lwcparser/fileutils/FileDiffUtil.ts b/src/utils/lwcparser/fileutils/FileDiffUtil.ts index c890212..775d5a2 100644 --- a/src/utils/lwcparser/fileutils/FileDiffUtil.ts +++ b/src/utils/lwcparser/fileutils/FileDiffUtil.ts @@ -45,11 +45,6 @@ export class FileDiffUtil { } escapeHtml(text: string): string { - return text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, '''); + return text.replace(/&/g, '&').replace(/(); // Read the JavaScript file const code = fs.readFileSync(filePath, 'utf-8'); + if (code.includes('Generated class DO NOT MODIFY')) { + return null; + } jsContentMap.set(FileConstant.BASE_CONTENT, code); // Parse the code into an AST (Abstract Syntax Tree) const ast = parser.parse(code, { diff --git a/src/utils/lwcparser/xmlParser/XmlParser.ts b/src/utils/lwcparser/xmlParser/XmlParser.ts index c9b8ccd..fb5480a 100644 --- a/src/utils/lwcparser/xmlParser/XmlParser.ts +++ b/src/utils/lwcparser/xmlParser/XmlParser.ts @@ -21,7 +21,7 @@ export class XmlParser { private parseXml(fileContent): void { const parser = new DOMParser(); try { - this.xmlDoc = parser.parseFromString(fileContent, 'text/xml'); + this.xmlDoc = parser.parseFromString(fileContent, 'application/xml'); } catch (error) { throw new Error('Error in xml parsing'); } @@ -29,7 +29,7 @@ export class XmlParser { public removeNode(tagName: string, index = 0): Map { const xmlContentMap = new Map(); - xmlContentMap.set(FileConstant.BASE_CONTENT, this.fileContent); + xmlContentMap.set(FileConstant.BASE_CONTENT, this.fileContent.replace('(/(<[^>]+?)/>/g', '$1 />')); if (!this.xmlDoc) { throw new Error('XML document has not been parsed.'); } @@ -41,6 +41,7 @@ export class XmlParser { const serializer = new XMLSerializer(); const xmlString: string = serializer.serializeToString(this.xmlDoc); + xmlString.replace(/(<[^>]+?)\/>/g, '$1 />'); xmlContentMap.set(FileConstant.MODIFIED_CONTENT, xmlString); return xmlContentMap; } diff --git a/src/utils/resultsbuilder/assessmentReporter.ts b/src/utils/resultsbuilder/assessmentReporter.ts index a93cb44..027140d 100644 --- a/src/utils/resultsbuilder/assessmentReporter.ts +++ b/src/utils/resultsbuilder/assessmentReporter.ts @@ -41,7 +41,7 @@ export class AssessmentReporter { ${changeInfoRows} `; const row = ` -
${lwcAssessmentInfo.name}
+
${lwcAssessmentInfo.name}
${changeInfoTable} `; tableBody += row; @@ -102,7 +102,7 @@ export class AssessmentReporter { private static getApexAssessmentReport(tableContent: string): string { const tableBody = ` -
+