Skip to content

Commit 1d55c6f

Browse files
Merge pull request #265 from salesforcecli/u/spachbhai/W-17149811/lwc-filter
@W-17149811 - LWC parsing filtering logic
2 parents c06ff88 + dea3cdf commit 1d55c6f

File tree

8 files changed

+134
-52
lines changed

8 files changed

+134
-52
lines changed

src/commands/omnistudio/migration/assess.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ export default class Assess extends OmniStudioBaseCommand {
6767
this.ux.log(`Using Namespace: ${namespace}`);
6868

6969
const dataRaptorAssessmentInfos: DataRaptorAssessmentInfo[] = await drMigrator.assess();
70-
this.ux.log('dataRaptorAssessmentInfos');
71-
this.ux.log(dataRaptorAssessmentInfos.toString());
70+
if (dataRaptorAssessmentInfos) {
71+
this.ux.log('dataRaptorAssessmentInfos');
72+
this.ux.log(dataRaptorAssessmentInfos.toString());
73+
}
7274
const flexCardAssessmentInfos: FlexCardAssessmentInfo[] = await flexMigrator.assess();
7375
const omniAssessmentInfo = await osMigrator.assess(dataRaptorAssessmentInfos, flexCardAssessmentInfos);
7476

src/migration/related/ApexMigration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class ApexMigration extends BaseRelatedObjectMigration {
3030
private readonly callableInterface: InterfaceImplements;
3131
private readonly vlocityOpenInterface2: InterfaceImplements;
3232
private readonly vlocityOpenInterface: InterfaceImplements;
33-
private updatedNamespace = 'omnistudio';
33+
private updatedNamespace = 'vlocity_ins';
3434
public constructor(projectPath: string, namespace: string, org: Org) {
3535
super(projectPath, namespace, org);
3636
this.callableInterface = new InterfaceImplements(CALLABLE, this.namespace);
@@ -52,7 +52,7 @@ export class ApexMigration extends BaseRelatedObjectMigration {
5252
const targetOrg: Org = this.org;
5353
sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
5454
const apexAssessmentInfos = this.processApexFiles(this.projectPath);
55-
// sfProject.deploy(APEXCLASS, targetOrg.getUsername());
55+
sfProject.deploy(APEXCLASS, targetOrg.getUsername());
5656
shell.cd(pwd);
5757
return apexAssessmentInfos;
5858
}

src/migration/related/LwcMigration.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-shadow */
12
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
23
import * as shell from 'shelljs';
34
import { Org } from '@salesforce/core';
@@ -26,7 +27,7 @@ export class LwcMigration extends BaseRelatedObjectMigration {
2627
const type = 'assessment';
2728
const pwd = shell.pwd();
2829
shell.cd(this.projectPath);
29-
sfProject.retrieve(LWCTYPE, this.org.getUsername());
30+
// sfProject.retrieve(LWCTYPE, this.org.getUsername());
3031
const filesMap = this.processLwcFiles(this.projectPath);
3132
shell.cd(pwd);
3233
return this.processFiles(filesMap, type);
@@ -49,7 +50,7 @@ export class LwcMigration extends BaseRelatedObjectMigration {
4950
dir += LWC_DIR_PATH;
5051
let filesMap: Map<string, File[]>;
5152
try {
52-
filesMap = fileutil.readAllFiles(dir);
53+
filesMap = fileutil.readAndProcessFiles(dir, 'OmniScript Auto-generated');
5354
} catch (error) {
5455
Logger.logger.error('Error in reading files', error);
5556
}
@@ -62,18 +63,24 @@ export class LwcMigration extends BaseRelatedObjectMigration {
6263
const jsonData: LWCAssessmentInfo[] = [];
6364
fileMap.forEach((fileList, dir) => {
6465
const changeInfos: FileChangeInfo[] = [];
65-
if (dir !== 'lwc' && !dir.endsWith('English') && !dir.includes('_') && !dir.startsWith('cf')) {
66+
if (
67+
dir !== 'lwc' &&
68+
!dir.endsWith('MultiLanguage') &&
69+
!dir.endsWith('English') &&
70+
!dir.includes('_') &&
71+
!dir.startsWith('cf') &&
72+
!dir.startsWith('Omniscript') &&
73+
!dir.includes('Util') &&
74+
!dir.includes('lodash')
75+
) {
6676
for (const file of fileList) {
6777
if (this.isValideFile(file.name)) {
6878
const processor = FileProcessorFactory.getFileProcessor(file.ext);
6979
if (processor != null) {
7080
const path = file.location;
7181
const name = file.name + file.ext;
72-
if (file.ext === 'xml') {
73-
// if (fileutil.isAutogenratedFile(path)) { }
74-
}
7582
const diff = processor.process(file, type, this.namespace);
76-
if (diff != null) {
83+
if (diff !== undefined && diff !== '') {
7784
const fileInfo: FileChangeInfo = {
7885
path,
7986
name,

src/utils/file/fileutil.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-return */
2+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
13
/* eslint-disable @typescript-eslint/restrict-template-expressions */
24
/* eslint-disable no-console */
35
import * as fs from 'fs';
@@ -71,6 +73,64 @@ export class fileutil {
7173
throw error;
7274
}
7375
}
76+
77+
public static readAndProcessFiles(
78+
baseDir: string,
79+
searchString: string,
80+
fileMap: Map<string, File[]> = new Map<string, File[]>()
81+
): Map<string, File[]> {
82+
const subDirectories = fs.readdirSync(baseDir).filter((dir) => {
83+
const fullPath = path.join(baseDir, dir);
84+
return fs.statSync(fullPath).isDirectory();
85+
});
86+
87+
for (const subDirectory of subDirectories) {
88+
console.log(`Processing subdirectory: ${subDirectory}`);
89+
const subDirPath = path.join(baseDir, subDirectory);
90+
91+
// Check the XML file for the substring
92+
const xmlFilePath = path.join(subDirPath, `${subDirectory}.js-meta.xml`);
93+
if (fs.existsSync(xmlFilePath)) {
94+
if (this.doesSubstringExist(xmlFilePath, searchString)) {
95+
console.log(`Substring found in ${xmlFilePath}. Skipping all files in ${subDirectory}.`);
96+
continue; // Move to the next subdirectory
97+
}
98+
}
99+
100+
// Process all files if substring is not found
101+
const currentDirFiles: File[] = [];
102+
const files = fs
103+
.readdirSync(subDirPath)
104+
.filter((file) => file.endsWith('.html') || file.endsWith('.js') || file.endsWith('.xml'));
105+
files.forEach((file) => {
106+
const filePath = path.join(subDirPath, file);
107+
console.log(`Processing file: ${filePath}`);
108+
const name = path.parse(file).name;
109+
const ext = path.parse(file).ext;
110+
const filepath = path.resolve(subDirPath, file);
111+
currentDirFiles.push(new File(name, filepath, ext));
112+
fileMap.set(path.basename(subDirPath), currentDirFiles);
113+
});
114+
}
115+
return fileMap;
116+
}
117+
118+
/**
119+
* Check if a substring exists in an XML file
120+
*
121+
* @param filePath Path of the XML file
122+
* @param searchString Substring to search for
123+
* @returns true if substring exists, otherwise false
124+
*/
125+
private static doesSubstringExist = (filePath: string, searchString: string): boolean => {
126+
try {
127+
const fileContent = fs.readFileSync(filePath, 'utf-8');
128+
return fileContent.includes(searchString);
129+
} catch (error) {
130+
console.error(`Error reading file ${filePath}:`, error);
131+
return false;
132+
}
133+
};
74134
}
75135

76136
export class File {

src/utils/formula/FormulaUtil.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ function getReplacedformulaString(
1717
const startParanthIndex = startIndex + formulaName.length;
1818
const endParanthIndex = getClosingIndexOfParantheses(formulaExpression, startParanthIndex);
1919
const newFormulaExpression =
20-
'Function(' +
21-
className +
20+
'FUNCTION(' +
21+
`'${className}'` +
2222
',' +
23-
methodName +
23+
`'${methodName}'` +
2424
',' +
2525
formulaExpression.substring(startParanthIndex + 1, endParanthIndex) +
2626
')';

src/utils/generatePackageXml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class generatePackageXml {
3838
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
3939
${apexXml}
4040
${lwcXml}
41-
${additionalTypes}
41+
${additionalTypes}
4242
<version>57.0</version>
4343
</Package>
4444
`;

src/utils/lwcparser/fileutils/FileDiffUtil.ts

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,59 @@
1-
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
2-
/* eslint-disable no-console */
31
/* eslint-disable @typescript-eslint/no-unsafe-call */
2+
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
3+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
44
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
55
import { createPatch } from 'diff';
6+
import { Logger } from '../../../utils/logger';
67

78
export class FileDiffUtil {
89
public getFileDiff(filename: string, originalFileContent: string, modifiedFileContent: string): string {
9-
const patch: string = createPatch(filename, originalFileContent, modifiedFileContent);
10-
11-
// Split the patch into lines
12-
const patchLines = patch.split('\n');
10+
const patch: string = createPatch('', originalFileContent, modifiedFileContent);
11+
try {
12+
// Split the patch into lines
13+
const patchLines = patch.split('\n');
1314

14-
// Initialize variables to track line numbers
15-
let oldLineNumber = 1;
16-
let newLineNumber = 1;
15+
// Initialize variables to track line numbers
16+
let oldLineNumber = 1;
17+
let newLineNumber = 1;
1718

18-
// Initialize result as HTML string
19-
let result = '';
19+
// Initialize result as HTML string
20+
let result = '';
2021

21-
patchLines.forEach((line) => {
22-
// Parse the hunk header (e.g., @@ -2,3 +2,3 @@)
23-
const hunkHeader = /^@@ -(\d+),\d+ \+(\d+),\d+ @@/;
24-
const match = hunkHeader.exec(line);
22+
patchLines.forEach((line) => {
23+
// Parse the hunk header (e.g., @@ -2,3 +2,3 @@)
24+
const hunkHeader = /^@@ -(\d+),\d+ \+(\d+),\d+ @@/;
25+
const match = hunkHeader.exec(line);
2526

26-
if (match) {
27-
oldLineNumber = parseInt(match[1], 10);
28-
newLineNumber = parseInt(match[2], 10);
29-
result += `<div>${this.escapeHtml(line)}</div>`;
30-
} else if (line.startsWith('-')) {
31-
result += `<div style="color: red;">- Line ${oldLineNumber}: ${this.escapeHtml(line.slice(1))}</div>`;
32-
oldLineNumber++;
33-
} else if (line.startsWith('+')) {
34-
result += `<div style="color: green;">+ Line ${newLineNumber}: ${this.escapeHtml(line.slice(1))}</div>`;
35-
newLineNumber++;
36-
} else if (line.startsWith(' ')) {
37-
// Unchanged line, just increment both line counters
38-
result += `<div>${this.escapeHtml(line)}</div>`;
39-
oldLineNumber++;
40-
newLineNumber++;
41-
}
42-
});
43-
// Return the result string with color codes
44-
return result;
27+
if (match) {
28+
oldLineNumber = parseInt(match[1], 10);
29+
newLineNumber = parseInt(match[2], 10);
30+
} else if (line.startsWith('-')) {
31+
// Skip the first line difference
32+
if (oldLineNumber === 1) {
33+
oldLineNumber++;
34+
return;
35+
}
36+
result += `<div style="color: red;">- Line ${oldLineNumber}: ${this.escapeHtml(line.slice(1))}</div>`;
37+
oldLineNumber++;
38+
} else if (line.startsWith('+')) {
39+
// Skip the first line difference
40+
if (newLineNumber === 1) {
41+
newLineNumber++;
42+
return;
43+
}
44+
result += `<div style="color: green;">+ Line ${newLineNumber}: ${this.escapeHtml(line.slice(1))}</div>`;
45+
newLineNumber++;
46+
} else if (line.startsWith(' ')) {
47+
// Unchanged line, skip it
48+
oldLineNumber++;
49+
newLineNumber++;
50+
}
51+
});
52+
// Return the result string, or an empty string if no differences
53+
return result.trim() ? result : '';
54+
} catch (error) {
55+
Logger.logger.error('Error in FileDiffUtil', error.message);
56+
}
4557
}
4658

4759
escapeHtml(text: string): string {

test/utils/formula/formulaUtil.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('FormulaUtilTest', () => {
1111
const inputString = "TESTMETHODFIRST('hello','bye')";
1212
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
1313
const result = getReplacedString(namespacePrefix, inputString, mockedFunctionDefinitionMetadata);
14-
const expectedResult = "Function(testClassFirst,testMethodFirst,'hello','bye')";
14+
const expectedResult = "FUNCTION('testClassFirst','testMethodFirst','hello','bye')";
1515

1616
expect(result).to.be.equal(expectedResult);
1717
});
@@ -23,7 +23,8 @@ describe('FormulaUtilTest', () => {
2323
const inputString = "TESTMETHODFIRST('hello',TESTMETHOD('bye'))";
2424
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
2525
const result = getReplacedString(namespacePrefix, inputString, mockedFunctionDefinitionMetadata);
26-
const expectedResult = "Function(testClassFirst,testMethodFirst,'hello',Function(testClass,testMethod,'bye'))";
26+
const expectedResult =
27+
"FUNCTION('testClassFirst','testMethodFirst','hello',FUNCTION('testClass','testMethod','bye'))";
2728

2829
expect(result).to.be.equal(expectedResult);
2930
});
@@ -36,7 +37,7 @@ describe('FormulaUtilTest', () => {
3637
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
3738
const result = getReplacedString(namespacePrefix, inputString, mockedFunctionDefinitionMetadata);
3839
const expectedResult =
39-
"Function(testClassFirst,testMethodFirst,'hello',Function(testClass,testMethod,Function(testClassFirst,testMethodFirst,'bye','check')))";
40+
"FUNCTION('testClassFirst','testMethodFirst','hello',FUNCTION('testClass','testMethod',FUNCTION('testClassFirst','testMethodFirst','bye','check')))";
4041
expect(result).to.be.equal(expectedResult);
4142
});
4243
});

0 commit comments

Comments
 (0)