Skip to content

Commit

Permalink
feat: filter the definition files
Browse files Browse the repository at this point in the history
  • Loading branch information
shailesh-sf committed Sep 24, 2024
1 parent ff762fe commit a132eca
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
32 changes: 20 additions & 12 deletions src/migration/related/LwcMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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');
}
}
7 changes: 1 addition & 6 deletions src/utils/lwcparser/fileutils/FileDiffUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ export class FileDiffUtil {
}

escapeHtml(text: string): string {
return text
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
}
}
5 changes: 0 additions & 5 deletions src/utils/lwcparser/jsParser/JavaScriptFileParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@ export class JavaScriptFileParser implements FileParser {
const jsParser = new JavaScriptParser();
return jsParser.replaceImportSource(filePath, namespace);
}

// saveToFile(filePath: string, content: string | undefined): void {
// const jsParser = new JavaScriptParser();
// jsParser.saveToFile(filePath, content);
// }
}
3 changes: 3 additions & 0 deletions src/utils/lwcparser/jsParser/JavaScriptParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export class JavaScriptParser {
const jsContentMap = new Map<string, string>();
// 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, {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/lwcparser/xmlParser/XmlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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');
}
}

public removeNode(tagName: string, index = 0): Map<string, string> {
const xmlContentMap = new Map<string, string>();
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.');
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/resultsbuilder/assessmentReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AssessmentReporter {
${changeInfoRows}
</table>`;
const row = `<tr class="slds-hint_parent">
<td><div class="slds-truncate" title="${lwcAssessmentInfo.name}">${lwcAssessmentInfo.name}</div></td>
<td><div class="slds-truncate slds-text-title_bold" title="${lwcAssessmentInfo.name}">${lwcAssessmentInfo.name}</div></td>
<td>${changeInfoTable}</td>
</tr>`;
tableBody += row;
Expand Down Expand Up @@ -102,7 +102,7 @@ export class AssessmentReporter {

private static getApexAssessmentReport(tableContent: string): string {
const tableBody = `
<div style="margin-block:15px">
<div style="margin-block:15px">
<table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped slds-table_col-bordered" aria-label="Results for Apex updates">
<thead>
<tr class="slds-line-height_reset">
Expand Down

0 comments on commit a132eca

Please sign in to comment.